-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathDataTable.spec.js
More file actions
48 lines (43 loc) · 1.37 KB
/
DataTable.spec.js
File metadata and controls
48 lines (43 loc) · 1.37 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.unmock('../DataTable');
jest.unmock('enzyme');
jest.unmock('sinon');
import { DataTable } from '../DataTable';
import React from 'react';
import { View, TextInput } from 'react-native';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import { ListView } from 'realm/react-native';
describe('DataTable', () => {
const dataSource = new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
});
beforeEach(() => {
dataSource.cloneWithRows(['row1', 'row2']);
});
it('renders a ListView', () => {
const wrapper = shallow(
<DataTable
dataSource={dataSource}
renderRow={jest.fn()}
/>
);
expect(wrapper.find(ListView).length).toEqual(1);
expect(wrapper.find(TextInput).length).toEqual(0); // No searchBar
expect(wrapper.prop('renderHeader')).toBeFalsy(); // No prop
});
describe('renderHeader', () => {
const renderHeader = sinon.spy(() => <View><Text>foo</Text></View>);
const wrapper = shallow(
<DataTable
dataSource={dataSource}
renderRow={jest.fn()}
renderHeader={() => renderHeader()}
/>
);
it('renders a header when given appropriate prop', () => {
expect(wrapper.contains('foo')).toEqual(true);
expect(wrapper.children().find(View).length).toEqual(1);
expect(wrapper.children().find(Text).length).toEqual(1);
});
});
});