-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuse-type.test.js
53 lines (39 loc) · 1.08 KB
/
use-type.test.js
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
import React from 'react';
import { mount } from '@bigtest/react';
import { Interactor, text, clickable } from '@bigtest/interactor';
import useType from './use-type';
const AppInteractor = Interactor.from({
text: text('span'),
clickIncrement: clickable('button')
});
let app = new AppInteractor();
it('renders and transitions microstate', async () => {
function App() {
let number = useType(Number, 42);
return (
<>
<span>{number.state}</span>
<button onClick={() => number.increment()}>Increment</button>
</>
);
}
await mount(() => <App />);
expect(app.text).toBe('42');
await app.clickIncrement();
expect(app.text).toBe('43');
});
it('defaults to Any when type is not specified', async () => {
function App() {
let s = useType();
return (
<>
<span>{`${s.state}`}</span>
<button onClick={() => s.set('hello world')}>Set message</button>
</>
);
}
await mount(() => <App />);
expect(app.text).toBe('undefined');
await app.clickIncrement();
expect(app.text).toBe('hello world');
});