Skip to content

Commit 10888f9

Browse files
committed
Fix ColorSchemeToggle.spec.js
1 parent 6f54bd6 commit 10888f9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

tests/unit/components/ColorSchemeToggle.spec.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ describe('ColorSchemeToggle', () => {
3434
supportsAutoColorScheme: true,
3535
},
3636
}),
37-
attachToDocument: true,
37+
attachTo: document.body,
3838
});
3939
});
4040

4141
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');
4344
});
4445

4546
it('renders a legend for fieldset', () => {
@@ -57,7 +58,7 @@ describe('ColorSchemeToggle', () => {
5758
expect(labels.at(2).text()).toBe('color-scheme.auto');
5859
});
5960

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 () => {
6162
const inputs = wrapper.findAll('input[type="radio"]');
6263
expect(inputs.length).toBe(3);
6364

@@ -71,39 +72,45 @@ describe('ColorSchemeToggle', () => {
7172
wrapper.setData({
7273
appState: { preferredColorScheme: dark },
7374
});
75+
await wrapper.vm.$nextTick();
7476
expect(inputs.at(0).element.checked).toBe(false);
7577
expect(inputs.at(1).element.checked).toBe(true);
7678
expect(inputs.at(2).element.checked).toBe(false);
7779

7880
wrapper.setData({
7981
appState: { preferredColorScheme: light },
8082
});
83+
await wrapper.vm.$nextTick();
8184
expect(inputs.at(0).element.checked).toBe(true);
8285
expect(inputs.at(1).element.checked).toBe(false);
8386
expect(inputs.at(2).element.checked).toBe(false);
8487
});
8588

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 () => {
8790
const darkInput = wrapper.findAll('input[type="radio"]').at(1);
88-
darkInput.setChecked();
91+
await darkInput.trigger('input');
8992
expect(AppStore.setPreferredColorScheme).toHaveBeenCalledWith(dark);
9093
});
9194

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 () => {
9396
expect(document.body.dataset.colorScheme).toBe(auto);
9497
wrapper.setData({
9598
appState: { preferredColorScheme: dark },
9699
});
100+
await wrapper.vm.$nextTick();
101+
97102
expect(document.body.dataset.colorScheme).toBe(dark);
98103
});
99104

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 () => {
101106
wrapper.setData({
102107
appState: {
103108
preferredColorScheme: light,
104109
supportsAutoColorScheme: false,
105110
},
106111
});
112+
await wrapper.vm.$nextTick();
113+
107114
const labels = wrapper.findAll('label');
108115
expect(labels.length).toBe(2);
109116

0 commit comments

Comments
 (0)