Navigation Menu

Skip to content

Commit

Permalink
Added context test from arthurdenner:feat/context-param-effect (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
cassiozen committed Jun 14, 2021
1 parent 40da2f4 commit a9b3633
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .all-contributorsrc
Expand Up @@ -77,7 +77,7 @@
]
}
],
"contributorsPerLine": 7,
"contributorsPerLine": 5,
"projectName": "useStateMachine",
"projectOwner": "cassiozen",
"repoType": "github",
Expand Down
27 changes: 27 additions & 0 deletions test/useStateMachine.test.tsx
Expand Up @@ -277,6 +277,33 @@ describe('useStateMachine', () => {
});
expect(effect.mock.calls[0][0]['event']).toStrictEqual({ type: 'ACTIVATE', number: 10 });
});
it('should invoke effect with context as a parameter', () => {
const finalEffect = jest.fn();
const initialEffect = jest.fn(({ setContext }) => {
setContext((context: boolean) => !context).send('TOGGLE');
});

renderHook(() =>
useStateMachine(false)({
initial: 'inactive',
states: {
inactive: {
on: { TOGGLE: 'active' },
effect: initialEffect,
},
active: {
effect: finalEffect,
},
},
})
);

expect(initialEffect).toHaveBeenCalledTimes(1);
expect(initialEffect.mock.calls[0][0]['context']).toBe(false);

expect(finalEffect).toHaveBeenCalledTimes(1);
expect(finalEffect.mock.calls[0][0]['context']).toBe(true);
});
});
describe('guarded transitions', () => {
it('should block transitions with guard returning false', () => {
Expand Down

0 comments on commit a9b3633

Please sign in to comment.