@@ -43,29 +43,40 @@ describe("Element focus", () => {
43
43
const input = document . body . appendChild ( document . createElement ( "input" ) ) ;
44
44
45
45
const machine = start ( ButtonFocusListener . bind ( null , button ) ) ;
46
-
47
- expect ( machine . current ) . toEqual ( "Inactive" ) ;
48
- expect ( machine . changeCount ) . toEqual ( 0 ) ;
46
+ expect ( machine . value ) . toMatchObject ( {
47
+ change : 0 ,
48
+ state : "Inactive" ,
49
+ } ) ;
49
50
50
51
button . focus ( ) ;
51
- expect ( machine . current ) . toEqual ( "Active" ) ;
52
- expect ( machine . changeCount ) . toEqual ( 2 ) ;
52
+ expect ( machine . value ) . toMatchObject ( {
53
+ change : 2 ,
54
+ state : "Active" ,
55
+ } ) ;
53
56
54
57
button . focus ( ) ;
55
- expect ( machine . current ) . toEqual ( "Active" ) ;
56
- expect ( machine . changeCount ) . toEqual ( 2 ) ;
58
+ expect ( machine . value ) . toMatchObject ( {
59
+ change : 2 ,
60
+ state : "Active" ,
61
+ } ) ;
57
62
58
63
input . focus ( ) ;
59
- expect ( machine . current ) . toEqual ( "Inactive" ) ;
60
- expect ( machine . changeCount ) . toEqual ( 4 ) ;
64
+ expect ( machine . value ) . toMatchObject ( {
65
+ change : 4 ,
66
+ state : "Inactive" ,
67
+ } ) ;
61
68
62
69
button . focus ( ) ;
63
- expect ( machine . current ) . toEqual ( "Active" ) ;
64
- expect ( machine . changeCount ) . toEqual ( 6 ) ;
70
+ expect ( machine . value ) . toMatchObject ( {
71
+ change : 6 ,
72
+ state : "Active" ,
73
+ } ) ;
65
74
66
75
button . blur ( ) ;
67
- expect ( machine . current ) . toEqual ( "Inactive" ) ;
68
- expect ( machine . changeCount ) . toEqual ( 8 ) ;
76
+ expect ( machine . value ) . toMatchObject ( {
77
+ change : 8 ,
78
+ state : "Inactive" ,
79
+ } ) ;
69
80
70
81
machine . abort ( ) ;
71
82
button . remove ( ) ;
@@ -77,9 +88,10 @@ describe("Element focus", () => {
77
88
78
89
button . focus ( ) ;
79
90
const machine = start ( ButtonFocusListener . bind ( null , button ) ) ;
80
-
81
- expect ( machine . current ) . toEqual ( "Active" ) ;
82
- expect ( machine . changeCount ) . toEqual ( 0 ) ;
91
+ expect ( machine . value ) . toMatchObject ( {
92
+ change : 0 ,
93
+ state : "Active" ,
94
+ } ) ;
83
95
84
96
button . remove ( ) ;
85
97
machine . abort ( ) ;
@@ -105,6 +117,7 @@ describe("Textbox validation", () => {
105
117
function * CheckingValid ( ) {
106
118
yield cond ( el . value === '' , InvalidCannotBeEmpty ) ;
107
119
yield cond ( / ^ [ a - z ] + $ / . test ( el . value ) === false , InvalidMustBeLowercase ) ;
120
+ // yield cond(false)(/^[a-z]+$/.test(el.value), InvalidMustBeLowercase);
108
121
yield always ( Valid ) ;
109
122
}
110
123
@@ -115,29 +128,40 @@ describe("Textbox validation", () => {
115
128
const input = document . body . appendChild ( document . createElement ( "input" ) ) ;
116
129
117
130
const machine = start ( RequiredInputValidationResponder . bind ( null , input ) ) ;
118
-
119
- expect ( machine . current ) . toEqual ( "Inactive" ) ;
120
- expect ( machine . changeCount ) . toEqual ( 0 ) ;
131
+ expect ( machine . value ) . toMatchObject ( {
132
+ change : 0 ,
133
+ state : "Inactive" ,
134
+ } ) ;
121
135
122
136
user . click ( input ) ;
123
- expect ( machine . current ) . toEqual ( "Active" ) ;
124
- expect ( machine . changeCount ) . toEqual ( 2 ) ;
137
+ expect ( machine . value ) . toMatchObject ( {
138
+ change : 2 ,
139
+ state : "Active" ,
140
+ } ) ;
125
141
126
142
user . click ( document . body ) ;
127
- expect ( machine . current ) . toEqual ( "Inactive" ) ;
128
- expect ( machine . changeCount ) . toEqual ( 4 ) ;
143
+ expect ( machine . value ) . toMatchObject ( {
144
+ change : 4 ,
145
+ state : "Inactive" ,
146
+ } ) ;
129
147
130
- user . type ( input , "hello" ) ;
131
- expect ( machine . current ) . toEqual ( "Valid" ) ;
148
+ user . paste ( input , "hello" ) ;
149
+ expect ( machine . value ) . toMatchObject ( {
150
+ change : 8 ,
151
+ state : "Valid" ,
152
+ } ) ;
132
153
133
154
user . clear ( input ) ;
134
- expect ( machine . current ) . toEqual ( "InvalidCannotBeEmpty" ) ;
155
+ expect ( machine . value ) . toMatchObject ( {
156
+ change : 10 ,
157
+ state : "InvalidCannotBeEmpty" ,
158
+ } ) ;
135
159
136
- user . type ( input , "HELLO" ) ;
137
- expect ( machine . current ) . toEqual ( "InvalidMustBeLowercase" ) ;
138
-
139
- user . type ( input , "lowercase" ) ;
140
- expect ( machine . current ) . toEqual ( "InvalidMustBeLowercase" ) ;
160
+ user . paste ( input , "HELLO" ) ;
161
+ expect ( machine . value ) . toMatchObject ( {
162
+ change : 12 ,
163
+ state : "InvalidMustBeLowercase" ,
164
+ } ) ;
141
165
142
166
input . remove ( ) ;
143
167
machine . abort ( ) ;
0 commit comments