|
1 | 1 | /** |
2 | 2 | * # Header-test.js |
3 | | - * |
| 3 | + * |
4 | 4 | * This class tests that the Header component displays correctly |
5 | 5 | * |
6 | 6 | * *Note:* if you want to understand the structures here, add a |
|
9 | 9 | */ |
10 | 10 | 'use strict'; |
11 | 11 |
|
12 | | -jest.autoMockOff(); |
| 12 | +jest.mock('ActivityIndicator', () => 'ActivityIndicator'); |
13 | 13 |
|
14 | 14 | /** |
15 | 15 | * ## Imports |
16 | 16 | */ |
17 | | -import React, { View } from 'react-native'; |
18 | | -import utils from 'react-addons-test-utils'; |
| 17 | +import 'react-native'; |
| 18 | +import React from 'react'; |
19 | 19 |
|
20 | | -/** |
21 | | - * ## Under test |
22 | | - * class under test |
23 | | - */ |
24 | | -jest.dontMock('../Header'); |
25 | | -var Header = require('../Header'); |
| 20 | +import Header from '../Header'; |
| 21 | + |
| 22 | +import renderer from 'react/lib/ReactTestRenderer'; |
26 | 23 |
|
27 | 24 | /** |
28 | 25 | * ## Test |
29 | 26 | */ |
30 | 27 | describe('Header', () => { |
31 | | - let header; |
32 | | - |
33 | | - /** |
34 | | - * ### renderHeader |
35 | | - * display component and return |
36 | | - * @returns {Object} with props, output and renderer |
37 | | - */ |
38 | | - |
39 | | - function renderHeader(props) { |
40 | | - const renderer = utils.createRenderer(); |
41 | | - renderer.render(<Header {...props}/>); |
42 | | - const output = renderer.getRenderOutput(); |
43 | | - |
44 | | - return { |
45 | | - props, |
46 | | - output, |
47 | | - renderer |
48 | | - }; |
49 | | - } |
50 | 28 | /** |
51 | 29 | * ### it should be display empty text when not fetching |
52 | 30 | * render the header when not fetching |
53 | | - */ |
| 31 | + */ |
54 | 32 | it('should be display empty text when not fetching', () => { |
55 | | - const buttonProps = { |
| 33 | + const props = { |
56 | 34 | isFetching: false |
57 | 35 | }; |
58 | | - header = renderHeader(buttonProps); |
59 | | - const {output} = header; |
60 | | - expect(output.type).toEqual(View); |
61 | | - expect(output.props.children[0].props.children[1].props.children).toEqual(' '); |
| 36 | + const tree = renderer.create(<Header {...props} />).toJSON(); |
| 37 | + expect(tree).toMatchSnapshot(); |
62 | 38 |
|
63 | 39 | }); |
64 | 40 | /** |
65 | 41 | * ### it should be display spinner when fetching |
66 | 42 | * When fetching, the GiftedSpinner should display |
67 | | - */ |
| 43 | + */ |
68 | 44 | it('should be display spinner when fetching', () => { |
69 | | - const buttonProps = { |
| 45 | + const props = { |
70 | 46 | isFetching: true |
71 | 47 | }; |
72 | | - header = renderHeader(buttonProps); |
73 | | - const {output} = header; |
74 | | - |
75 | | - expect(output.type).toEqual(View); |
76 | | - let animating = |
77 | | - output.props.children[0].props.children[1].props.animating; |
78 | | - let size = output.props.children[0].props.children[1].props.size; |
79 | | - |
80 | 48 |
|
81 | | - expect(animating).toEqual(true); |
82 | | - expect(size).toEqual('large'); |
83 | | - |
84 | | - //expect(output.props.children[0].props.children[1].type.displayName).toEqual('GiftedSpinner'); |
| 49 | + const tree = renderer.create(<Header {...props} />).toJSON(); |
| 50 | + expect(tree).toMatchSnapshot(); |
85 | 51 | }); |
86 | 52 |
|
87 | 53 | });//describe Header |
0 commit comments