This repository has been archived by the owner on Dec 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
search_bar.spec.tsx
58 lines (52 loc) · 1.7 KB
/
search_bar.spec.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
56
57
58
import React from 'react';
import { mount, ReactWrapper } from 'enzyme';
import { SearchBar } from '..';
// Use real timers for this one because https://github.com/facebook/jest/issues/3465
describe('search_bar.tsx', () => {
let wrapper: ReactWrapper;
let emitDelay: number;
const query = 'hello world';
const placeholder = 'For example…';
const onChange: jest.Mock<any, any> = jest.fn();
afterEach(() => {
onChange.mockReset();
wrapper.unmount();
});
test('snapshot and instance', () => {
wrapper = mount(<SearchBar onChange={onChange} placeholder={placeholder} />);
expect(wrapper.instance()).toBeInstanceOf(SearchBar);
expect(wrapper).toMatchSnapshot();
});
test('with "query" prop', (done) => {
wrapper = mount(
<SearchBar
onChange={onChange}
placeholder={placeholder}
query={query}
/>,
);
expect(onChange).not.toHaveBeenCalled();
setTimeout(() => {
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(query);
done();
}, 0);
});
test('with "emitDelay" prop', (done) => {
emitDelay = 500;
wrapper = mount(
<SearchBar
onChange={onChange}
placeholder={placeholder}
emitDelay={emitDelay}
query={query}
/>,
);
expect(onChange).not.toHaveBeenCalled();
setTimeout(() => {
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(query);
done();
}, emitDelay);
});
});