@@ -52,6 +52,50 @@ QUnit.module('Invoke', hooks => {
52
52
assert . equal ( service . machine . current , 'two' , 'in the new state' ) ;
53
53
} ) ;
54
54
55
+ QUnit . test ( 'Should not fire "done" event when state changes' , async assert => {
56
+ const wait = ms => ( ) => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
57
+
58
+ let machine = createMachine ( {
59
+ one : state ( transition ( 'click' , 'two' ) ) ,
60
+ two : invoke ( wait ( 10 ) ,
61
+ transition ( 'done' , 'one' ) ,
62
+ transition ( 'click' , 'three' )
63
+ ) ,
64
+ three : state (
65
+ transition ( 'done' , 'error' ) ,
66
+ ) ,
67
+ error : state ( ) ,
68
+ } ) ;
69
+
70
+ let service = interpret ( machine , ( ) => { } ) ;
71
+ service . send ( 'click' ) ;
72
+ service . send ( 'click' ) ;
73
+ await wait ( 15 ) ( )
74
+ assert . equal ( service . machine . current , 'three' , 'now in the next state' ) ;
75
+ } ) ;
76
+
77
+ QUnit . test ( 'Should fire "done" when context changes' , async assert => {
78
+ const wait = ms => ( ) => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
79
+
80
+ let machine = createMachine ( {
81
+ one : state ( transition ( 'click' , 'two' ) ) ,
82
+ two : invoke ( wait ( 10 ) ,
83
+ transition ( 'done' , 'three' ) ,
84
+ transition ( 'click' , 'two' , reduce ( ( ctx ) => ( { value : ctx . value + 1 } ) ) )
85
+ ) ,
86
+ three : state ( ) ,
87
+ error : state ( ) ,
88
+ } , ( ) => ( { value : 0 } ) ) ;
89
+
90
+ let service = interpret ( machine , ( ) => { } ) ;
91
+ service . send ( 'click' ) ;
92
+ service . send ( 'click' ) ;
93
+ service . send ( 'click' ) ;
94
+ await wait ( 15 ) ( )
95
+ assert . equal ( service . context . value , 2 , 'value should be 2' ) ;
96
+ assert . equal ( service . machine . current , 'three' , 'now in the correct state' ) ;
97
+ } ) ;
98
+
55
99
QUnit . module ( 'Machine' ) ;
56
100
57
101
QUnit . test ( 'Can invoke a child machine' , async assert => {
0 commit comments