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