forked from mfellner/valtio-factory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.test.tsx
More file actions
48 lines (36 loc) · 1.36 KB
/
app.test.tsx
File metadata and controls
48 lines (36 loc) · 1.36 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
/**
* @jest-environment jsdom
*/
import '@testing-library/jest-dom/extend-expect';
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import App from './app';
import { root } from './model';
import { StoreProvider } from './store-provider';
/* eslint-disable valtio/state-snapshot-rule */
const getRandomNumber = () => 1;
describe('App', () => {
test('increment and reset', async () => {
const rootStore = root.create({ getRandomNumber }, { counter: { count: 0 } });
render(
<StoreProvider rootStore={rootStore}>
<App />
</StoreProvider>,
);
fireEvent.click(screen.getByText('increment'));
expect(await screen.findByTestId('count')).toHaveTextContent('The current count is 1');
fireEvent.click(screen.getByText('reset'));
expect(await screen.findByTestId('count')).toHaveTextContent('The current count is 0');
});
test('input text', async () => {
const rootStore = root.create({ getRandomNumber }, { counter: { count: 0 } });
const { findByTestId } = render(
<StoreProvider rootStore={rootStore}>
<App />
</StoreProvider>,
);
fireEvent.change(screen.getByLabelText('user-input'), { target: { value: 'Test' } });
expect(await findByTestId('user-label')).toHaveTextContent('Test');
expect(rootStore.user.user?.name).toBe('Test');
});
});