1
- import React from ' react' ;
2
- import renderer from ' react-test-renderer' ;
3
- import { MockedProvider } from ' ../../../lib/test-utils' ;
4
- import { print } from ' graphql' ;
5
- import { addTypenameToDocument } from ' apollo-client/queries/queryTransform' ;
1
+ import React from " react" ;
2
+ import renderer from " react-test-renderer" ;
3
+ import { MockedProvider } from " ../../../lib/react-apollo. test-utils.umd" ;
4
+ import { print } from " graphql" ;
5
+ import { addTypenameToDocument } from " apollo-client/queries/queryTransform" ;
6
6
7
- import PokemonWithData , { POKEMON_QUERY , Pokemon , withPokemon } from './Pokemon' ;
7
+ import PokemonWithData , {
8
+ POKEMON_QUERY ,
9
+ Pokemon ,
10
+ withPokemon ,
11
+ } from "./Pokemon" ;
8
12
9
13
const mockedData = {
10
14
pokemon : {
11
- __typename : ' Pokemon' ,
12
- name : ' Charmander' ,
13
- image : ' https://img.pokemondb.net/artwork/charmander.jpg' ,
15
+ __typename : " Pokemon" ,
16
+ name : " Charmander" ,
17
+ image : " https://img.pokemondb.net/artwork/charmander.jpg" ,
14
18
} ,
15
19
} ;
16
20
17
21
const query = addTypenameToDocument ( POKEMON_QUERY ) ;
18
- const variables = { name : ' charmander' } ;
22
+ const variables = { name : " charmander" } ;
19
23
20
- describe ( ' default export' , ( ) => {
21
- it ( ' renders without crashing' , ( ) => {
24
+ describe ( " default export" , ( ) => {
25
+ it ( " renders without crashing" , ( ) => {
22
26
const output = renderer . create (
23
- < MockedProvider mocks = { [
24
- { request : { query, variables } , result : { data : mockedData } }
25
- ] } >
27
+ < MockedProvider
28
+ mocks = { [
29
+ { request : { query, variables } , result : { data : mockedData } } ,
30
+ ] }
31
+ >
26
32
< PokemonWithData />
27
33
</ MockedProvider >
28
- )
34
+ ) ;
29
35
expect ( output . toJSON ( ) ) . toMatchSnapshot ( ) ;
30
36
} ) ;
31
37
} ) ;
32
38
33
- describe ( ' Pokemon enhancer' , ( ) => {
34
- it ( ' renders with loading first' , ( done ) => {
39
+ describe ( " Pokemon enhancer" , ( ) => {
40
+ it ( " renders with loading first" , done => {
35
41
class Container extends React . Component {
36
42
componentWillMount ( ) {
37
43
expect ( this . props . data . loading ) . toBe ( true ) ;
@@ -41,18 +47,20 @@ describe('Pokemon enhancer', () => {
41
47
render ( ) {
42
48
return null ;
43
49
}
44
- } ;
50
+ }
45
51
const ContainerWithData = withPokemon ( Container ) ;
46
52
const output = renderer . create (
47
- < MockedProvider mocks = { [
48
- { request : { query, variables } , result : { data : mockedData } } ]
49
- } >
53
+ < MockedProvider
54
+ mocks = { [
55
+ { request : { query, variables } , result : { data : mockedData } } ,
56
+ ] }
57
+ >
50
58
< ContainerWithData />
51
59
</ MockedProvider >
52
60
) ;
53
61
} ) ;
54
62
55
- it ( ' renders data without crashing' , ( done ) => {
63
+ it ( " renders data without crashing" , done => {
56
64
class Container extends React . Component {
57
65
componentWillReceiveProps ( props ) {
58
66
expect ( props . data . loading ) . toBe ( false ) ;
@@ -62,18 +70,20 @@ describe('Pokemon enhancer', () => {
62
70
render ( ) {
63
71
return null ;
64
72
}
65
- } ;
73
+ }
66
74
const ContainerWithData = withPokemon ( Container ) ;
67
75
const output = renderer . create (
68
- < MockedProvider mocks = { [
69
- { request : { query, variables } , result : { data : mockedData } }
70
- ] } >
76
+ < MockedProvider
77
+ mocks = { [
78
+ { request : { query, variables } , result : { data : mockedData } } ,
79
+ ] }
80
+ >
71
81
< ContainerWithData />
72
82
</ MockedProvider >
73
83
) ;
74
84
} ) ;
75
85
76
- it ( ' renders with an error correctly' , ( done ) => {
86
+ it ( " renders with an error correctly" , done => {
77
87
try {
78
88
class Container extends React . Component {
79
89
componentWillReceiveProps ( props ) {
@@ -83,12 +93,12 @@ describe('Pokemon enhancer', () => {
83
93
render ( ) {
84
94
return null ;
85
95
}
86
- } ;
96
+ }
87
97
const ContainerWithData = withPokemon ( Container ) ;
88
98
const output = renderer . create (
89
- < MockedProvider mocks = { [
90
- { request : { query, variables } , error : new Error ( ' fail' ) }
91
- ] } >
99
+ < MockedProvider
100
+ mocks = { [ { request : { query, variables } , error : new Error ( " fail" ) } ] }
101
+ >
92
102
< ContainerWithData />
93
103
</ MockedProvider >
94
104
) ;
@@ -98,33 +108,33 @@ describe('Pokemon enhancer', () => {
98
108
} ) ;
99
109
} ) ;
100
110
101
- describe ( ' Pokemon query' , ( ) => {
111
+ describe ( " Pokemon query" , ( ) => {
102
112
// it('should match expected structure', () => {
103
113
// expect(POKEMON_QUERY).toMatchSnapshot();
104
114
// });
105
115
106
- it ( ' should match expected shape' , ( ) => {
116
+ it ( " should match expected shape" , ( ) => {
107
117
expect ( print ( POKEMON_QUERY ) ) . toMatchSnapshot ( ) ;
108
118
} ) ;
109
119
} ) ;
110
120
111
- describe ( ' Pokemon Component' , ( ) => {
112
- it ( ' should render a loading state without data' , ( ) => {
113
- const output = renderer . create ( < Pokemon data = { { loading : true } } /> )
121
+ describe ( " Pokemon Component" , ( ) => {
122
+ it ( " should render a loading state without data" , ( ) => {
123
+ const output = renderer . create ( < Pokemon data = { { loading : true } } /> ) ;
114
124
expect ( output . toJSON ( ) ) . toMatchSnapshot ( ) ;
115
125
} ) ;
116
126
117
- it ( 'should render an error' , ( ) => {
118
- const output = renderer . create ( < Pokemon data = { { error : new Error ( "ERROR" ) } } /> )
127
+ it ( "should render an error" , ( ) => {
128
+ const output = renderer . create (
129
+ < Pokemon data = { { error : new Error ( "ERROR" ) } } />
130
+ ) ;
119
131
expect ( output . toJSON ( ) ) . toMatchSnapshot ( ) ;
120
132
} ) ;
121
133
122
- it ( ' should render name and image in order' , ( ) => {
134
+ it ( " should render name and image in order" , ( ) => {
123
135
const output = renderer . create (
124
136
< Pokemon data = { { loading : false , content : mockedData . pokemon } } />
125
137
) ;
126
138
expect ( output . toJSON ( ) ) . toMatchSnapshot ( ) ;
127
139
} ) ;
128
140
} ) ;
129
-
130
-
0 commit comments