@@ -34,12 +34,13 @@ describe('ColorSchemeToggle', () => {
34
34
supportsAutoColorScheme : true ,
35
35
} ,
36
36
} ) ,
37
- attachToDocument : true ,
37
+ attachTo : document . body ,
38
38
} ) ;
39
39
} ) ;
40
40
41
41
it ( 'renders a fieldset .color-scheme-toggle' , ( ) => {
42
- expect ( wrapper . is ( 'fieldset.color-scheme-toggle' ) ) ;
42
+ expect ( wrapper . element . tagName . toLowerCase ( ) ) . toBe ( 'fieldset' ) ;
43
+ expect ( wrapper . classes ( ) ) . toContain ( 'color-scheme-toggle' ) ;
43
44
} ) ;
44
45
45
46
it ( 'renders a legend for fieldset' , ( ) => {
@@ -57,7 +58,7 @@ describe('ColorSchemeToggle', () => {
57
58
expect ( labels . at ( 2 ) . text ( ) ) . toBe ( 'color-scheme.auto' ) ;
58
59
} ) ;
59
60
60
- it ( 'renders radio buttons checked according to the preferred color scheme' , ( ) => {
61
+ it ( 'renders radio buttons checked according to the preferred color scheme' , async ( ) => {
61
62
const inputs = wrapper . findAll ( 'input[type="radio"]' ) ;
62
63
expect ( inputs . length ) . toBe ( 3 ) ;
63
64
@@ -71,39 +72,45 @@ describe('ColorSchemeToggle', () => {
71
72
wrapper . setData ( {
72
73
appState : { preferredColorScheme : dark } ,
73
74
} ) ;
75
+ await wrapper . vm . $nextTick ( ) ;
74
76
expect ( inputs . at ( 0 ) . element . checked ) . toBe ( false ) ;
75
77
expect ( inputs . at ( 1 ) . element . checked ) . toBe ( true ) ;
76
78
expect ( inputs . at ( 2 ) . element . checked ) . toBe ( false ) ;
77
79
78
80
wrapper . setData ( {
79
81
appState : { preferredColorScheme : light } ,
80
82
} ) ;
83
+ await wrapper . vm . $nextTick ( ) ;
81
84
expect ( inputs . at ( 0 ) . element . checked ) . toBe ( true ) ;
82
85
expect ( inputs . at ( 1 ) . element . checked ) . toBe ( false ) ;
83
86
expect ( inputs . at ( 2 ) . element . checked ) . toBe ( false ) ;
84
87
} ) ;
85
88
86
- it ( 'sets the preferred color scheme when a radio button is checked' , ( ) => {
89
+ it ( 'sets the preferred color scheme when a radio button is checked' , async ( ) => {
87
90
const darkInput = wrapper . findAll ( 'input[type="radio"]' ) . at ( 1 ) ;
88
- darkInput . setChecked ( ) ;
91
+ await darkInput . trigger ( 'input' ) ;
89
92
expect ( AppStore . setPreferredColorScheme ) . toHaveBeenCalledWith ( dark ) ;
90
93
} ) ;
91
94
92
- it ( 'sets body[data-color-scheme] to match the preferred color scheme' , ( ) => {
95
+ it ( 'sets body[data-color-scheme] to match the preferred color scheme' , async ( ) => {
93
96
expect ( document . body . dataset . colorScheme ) . toBe ( auto ) ;
94
97
wrapper . setData ( {
95
98
appState : { preferredColorScheme : dark } ,
96
99
} ) ;
100
+ await wrapper . vm . $nextTick ( ) ;
101
+
97
102
expect ( document . body . dataset . colorScheme ) . toBe ( dark ) ;
98
103
} ) ;
99
104
100
- it ( 'only render Light/Dark options when Auto is not supported by device' , ( ) => {
105
+ it ( 'only render Light/Dark options when Auto is not supported by device' , async ( ) => {
101
106
wrapper . setData ( {
102
107
appState : {
103
108
preferredColorScheme : light ,
104
109
supportsAutoColorScheme : false ,
105
110
} ,
106
111
} ) ;
112
+ await wrapper . vm . $nextTick ( ) ;
113
+
107
114
const labels = wrapper . findAll ( 'label' ) ;
108
115
expect ( labels . length ) . toBe ( 2 ) ;
109
116
0 commit comments