deno.land / x / xstate@xstate@4.33.6 / test / eventDescriptors.test.ts

eventDescriptors.test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Machine, interpret } from '../src/index';
describe('event descriptors', () => { it('should fallback to using wildcard transition definition (if specified)', () => { const machine = Machine({ initial: 'A', states: { A: { on: { FOO: 'B', '*': 'C' } }, B: {}, C: {} } });
const service = interpret(machine).start(); service.send('BAR'); expect(service.state.value).toBe('C'); });
it('should not use wildcard transition over explicit one when using object `.on` config - even if wildcard comes first', () => { const machine = Machine({ initial: 'A', states: { A: { on: { '*': 'fail', NEXT: 'pass' } }, fail: {}, pass: {} } });
const service = interpret(machine).start(); service.send('NEXT'); expect(service.state.value).toBe('pass'); });
it('should select wildcard over explicit event type for array `.on` config (according to document order)', () => { const machine = Machine({ initial: 'A', states: { A: { on: [ { event: '*', target: 'pass' }, { event: 'NEXT', target: 'fail' } ] }, fail: {}, pass: {} } });
const service = interpret(machine).start(); service.send('NEXT'); expect(service.state.value).toBe('pass'); });});
xstate

Version Info

Tagged at
2 years ago