forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
87 lines (63 loc) · 2.2 KB
/
index.test.ts
File metadata and controls
87 lines (63 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import '@testing-library/jest-dom/extend-expect'
import { render, fireEvent } from '@testing-library/svelte'
import { Overmind } from 'overmind'
import { createMixin } from './'
import CountTest from './CountTest.svelte'
const app = {
state: {
count: 0
},
actions: {
increase({ state }) {
state.count++;
},
decrease({ state }) {
state.count--;
}
}
}
describe('Svelte', () => {
test('should create mixin', () => {
const overmind = new Overmind(app)
const mixin = createMixin(overmind)
expect('state' in mixin)
})
test('should expose subscribe', () => {
const overmind = new Overmind(app)
const mixin = createMixin(overmind)
expect(typeof mixin.state.subscribe === 'function')
})
test('should display current state', () => {
const overmind = new Overmind(app)
const mixin = createMixin(overmind)
const { getByText, getAllByRole } = render(CountTest, { store: mixin })
expect(getByText('Count: 0')).toBeInTheDocument()
})
test('should update state by button click', async () => {
const overmind = new Overmind(app)
const mixin = createMixin(overmind)
const { getAllByRole } = render(CountTest, { store: mixin })
const [increaseBtn, ] = getAllByRole('button')
await fireEvent.click(increaseBtn)
await fireEvent.click(increaseBtn)
expect(mixin.state.count === 2)
})
test('should update view on state change', async () => {
const overmind = new Overmind(app)
const mixin = createMixin(overmind)
const { getByText, getAllByRole } = render(CountTest, { store: mixin })
const [increaseBtn, decreaseBtn] = getAllByRole('button')
await fireEvent.click(increaseBtn)
expect(getByText('Count: 1')).toBeInTheDocument()
})
test('should update view on reaction', async () => {
const overmind = new Overmind(app)
const mixin = createMixin(overmind)
const { getByText, getAllByRole } = render(CountTest, { store: mixin })
const [increaseBtn, ] = getAllByRole('button')
expect(getByText('Doubled: 0')).toBeInTheDocument()
await fireEvent.click(increaseBtn)
await fireEvent.click(increaseBtn)
expect(getByText('Doubled: 4')).toBeInTheDocument()
})
})