-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathindex.test.tsx
55 lines (46 loc) · 1.4 KB
/
index.test.tsx
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
import { render, screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import { describe, expect, test } from 'vitest';
import { useFunnel } from '../src/index.js';
describe('Test useFunnel next-app-router router', () => {
test('should work', async () => {
function FunnelTest() {
const funnel = useFunnel<{
A: { id?: string };
B: { id: string };
}>({
id: 'vitest',
initial: {
step: 'A',
context: {},
},
});
switch (funnel.step) {
case 'A': {
return <button onClick={() => funnel.history.push('B', { id: 'vitest' })}>Go B</button>;
}
case 'B': {
return (
<div>
<button onClick={() => window.history.back()}>Go Back</button>
<div>{funnel.context.id}</div>
</div>
);
}
default: {
throw new Error('Invalid step');
}
}
}
render(<FunnelTest />);
expect(screen.queryByText('Go B')).not.toBeNull();
const user = userEvent.setup();
await user.click(screen.getByText('Go B'));
expect(screen.queryByText('vitest')).not.toBeNull();
await user.click(screen.getByText('Go Back'));
expect(screen.queryByText('vitest')).toBeNull();
expect(screen.queryByText('Go B')).not.toBeNull();
});
test('hello' , async () => {
})
});