Skip to content

Commit cba6f24

Browse files
committed
test(middleware): add test for customizing model's middleware
1 parent 1f1d243 commit cba6f24

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

__test__/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export const ErrorCounter: ModelType<CounterState, CounterActionParams> = {
151151
}
152152

153153
const delayMiddleware: Middleware = async (context, restMiddlewares) => {
154-
await timeout(2000, {})
154+
await timeout(1000, {})
155155
context.next(restMiddlewares)
156156
}
157157

__test__/middlewares/model.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ import { Model } from '../../src'
77

88
describe('NextModel', () => {
99
test("allows you to customize model's middleware", async () => {
10-
let actions: any
11-
let state: any
12-
const { useStore, getActions } = Model({ NextCounterModel })
10+
let actions: any, nextActions: any
11+
let state: any, nextState: any
12+
const WrapperModel = Model(NextCounterModel)
13+
const { useStore, getActions } = Model({ NextCounterModel, WrapperModel })
1314
const beginTime = Date.now()
1415
renderHook(() => {
1516
;[state, actions] = useStore('NextCounterModel')
17+
;[nextState, nextActions] = useStore('WrapperModel')
1618
})
1719
await actions.increment(2)
1820
await getActions('NextCounterModel').increment(1)
1921
expect(Date.now() - beginTime > 300)
2022
expect(state.count).toBe(3)
23+
await nextActions.increment(2)
24+
await getActions('WrapperModel').increment(1)
25+
expect(nextState.count).toBe(3)
2126
})
2227
})

0 commit comments

Comments
 (0)