Created
August 20, 2020 14:00
-
-
Save SuperOleg39/d8855a42299da9598abbea9a010e09a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { appSimulator } from '@tramvai/test'; | |
| import { createAction } from '@tramvai/core'; | |
| import { createReducer, createEvent } from '@tramvai/state'; | |
| import { CommonModule } from '@tramvai/module-common'; | |
| import { actionServerStateEvent } from '@tramvai/module-common/lib/actions/actionTramvaiReducer'; | |
| import { CONTEXT_TOKEN, COMBINE_REDUCERS } from '@tramvai/tokens-common'; | |
| const incrementEvent = createEvent('increment'); | |
| const testReducer = createReducer('test', { | |
| count: 0, | |
| }).on(incrementEvent, (state) => ({ | |
| count: state.count + 1, | |
| })); | |
| const action = createAction({ | |
| name: 'test', | |
| async fn(ctx) { | |
| await ctx.dispatch( | |
| actionServerStateEvent({ | |
| foo: true, | |
| }) | |
| ); | |
| await ctx.dispatch(incrementEvent()); | |
| }, | |
| }); | |
| describe('test', () => { | |
| it('context', async () => { | |
| const { getToken } = appSimulator({ | |
| modules: [CommonModule], | |
| providers: [ | |
| { | |
| provide: COMBINE_REDUCERS, | |
| multi: true, | |
| useValue: testReducer, | |
| }, | |
| ], | |
| }); | |
| const context = getToken(CONTEXT_TOKEN); | |
| expect(context.getState().actionTramvai.serverState.foo).toBeUndefined(); | |
| expect(context.getState().test.count).toBe(0); | |
| await context.executeAction(action); | |
| expect(context.getState().actionTramvai.serverState.foo).toBe(true); | |
| expect(context.getState().test.count).toBe(1); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment