-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.test.tsx
50 lines (41 loc) · 1.24 KB
/
tester.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
/* global it, describe, expect */
import React, { Component } from 'react';
import { Tester } from '../src';
import { sleep } from '../src/utils';
const COMPONENT_ID = 'testing-component';
const MyTestingComponent = (props: any) => <div id={COMPONENT_ID} {...props} />;
class AsyncComponent extends Component {
public constructor (props: object) {
super(props);
this.state = { status: 'loading' };
}
public async componentDidMount () {
await sleep(10);
this.setState({
status: 'done',
});
}
public render () {
return (
<div>
{this.state.status}
</div>
);
}
}
describe('Tester', () => {
it('Init tests', async () => {
const tester = await new Tester(MyTestingComponent).mount();
expect(tester.wrapper).toBeTruthy();
expect(tester.html()).toContain(COMPONENT_ID);
});
it('Init tests TestHook', async () => {
const tester = await new (Tester as any).TestProfile(MyTestingComponent).mount();
expect(tester.wrapper).toBeTruthy();
expect(tester.wrapper.html()).toContain('test-hook-component');
});
it('Awaits async componentDidMount', async () => {
const tester = await new Tester(AsyncComponent).mount();
expect(tester.text()).toContain('done');
});
});