Skip to content

Commit

Permalink
Add context tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Sep 10, 2021
1 parent 648435c commit 65c7e62
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/core/test/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,41 @@ describe('State', () => {
expect(machine.initialState.can({ type: 'NEXT' })).toBe(true);
});

it('should return true for an event object that results in a new action', () => {
const machine = createMachine({
initial: 'a',
states: {
a: {
on: {
NEXT: {
actions: 'newAction'
}
}
}
}
});

expect(machine.initialState.can({ type: 'NEXT' })).toBe(true);
});

it('should return true for an event object that results in a context change', () => {
const machine = createMachine({
initial: 'a',
context: { count: 0 },
states: {
a: {
on: {
NEXT: {
actions: assign({ count: 1 })
}
}
}
}
});

expect(machine.initialState.can({ type: 'NEXT' })).toBe(true);
});

it('should return false for an external self-transition without actions', () => {
const machine = createMachine({
initial: 'a',
Expand Down

0 comments on commit 65c7e62

Please sign in to comment.