Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit cf2008c

Browse files
committed
test(colomode): add colormode tests
1 parent 1c723a9 commit cf2008c

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`should toggle colormode 1`] = `
4+
<DocumentFragment>
5+
<div>
6+
<div
7+
data-testid="colormode"
8+
>
9+
dark
10+
</div>
11+
<button
12+
data-testid="toggle"
13+
>
14+
Toggle color mode
15+
</button>
16+
</div>
17+
</DocumentFragment>
18+
`;
Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1-
import { CColorMode } from '../'
1+
import { defineComponent, nextTick } from 'vue'
2+
import { render, userEvent } from '../../test-utils/src'
3+
import { useColorMode } from '../src'
24

5+
const renderComponent = (props?: any) => {
6+
const base = defineComponent({
7+
template: `
8+
<div>
9+
<div data-testid="colormode"> {{ colorMode }} </div>
10+
<button data-testid="toggle" @click="toggleColorMode">Toggle color mode</button>
11+
</div>
12+
`,
13+
setup() {
14+
const { colorMode, toggleColorMode } = useColorMode()
15+
return {
16+
colorMode,
17+
toggleColorMode,
18+
}
19+
},
20+
...props,
21+
})
22+
return render(base)
23+
}
324

4-
it('should be truthy', () => {
5-
expect(1).toBe(1)
6-
})
25+
it('should toggle colormode', async () => {
26+
const { getByTestId, asFragment } = renderComponent()
27+
expect(getByTestId('colormode').textContent).toBe('light')
28+
29+
await userEvent.click(getByTestId('toggle'))
30+
await nextTick()
31+
expect(getByTestId('colormode').textContent).toBe('dark')
32+
33+
expect(asFragment()).toMatchSnapshot()
34+
})

0 commit comments

Comments
 (0)