File tree Expand file tree Collapse file tree 3 files changed +51
-1
lines changed Expand file tree Collapse file tree 3 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 17
17
"build:lib" : " babel src --out-dir lib" ,
18
18
"build:dist" : " webpack src/index.js dist/react-async-loading.min.js" ,
19
19
"build:example" : " webpack --config ./example/webpack.config.js" ,
20
+ "test" : " ava --verbose" ,
20
21
"clean" : " rimraf lib dist" ,
21
- "prepublish" : " npm run clean && npm run build"
22
+ "prepublish" : " npm run test && npm run clean && npm run build"
22
23
},
23
24
"repository" : {
24
25
"type" : " git" ,
29
30
" dist" ,
30
31
" src"
31
32
],
33
+ "ava" : {
34
+ "require" : " ./test/helpers/setup-test-env.js" ,
35
+ "babel" : " inherit"
36
+ },
32
37
"devDependencies" : {
38
+ "ava" : " 0.16.0" ,
33
39
"babel-cli" : " 6.14.0" ,
34
40
"babel-core" : " 6.14.0" ,
35
41
"babel-loader" : " 6.2.5" ,
36
42
"babel-preset-es2015" : " 6.14.0" ,
37
43
"babel-preset-react" : " 6.11.1" ,
44
+ "babel-register" : " 6.14.0" ,
45
+ "enzyme" : " 2.4.1" ,
46
+ "jsdom" : " 9.4.5" ,
38
47
"react" : " 15.3.1" ,
48
+ "react-addons-test-utils" : " 15.3.1" ,
39
49
"react-dom" : " 15.3.1" ,
40
50
"rimraf" : " 2.5.4" ,
41
51
"webpack" : " 2.1.0-beta.21"
Original file line number Diff line number Diff line change
1
+ import test from 'ava' ;
2
+ import React from 'react' ;
3
+ import { mount , shallow } from 'enzyme' ;
4
+ import asyncComponent from '../src/asyncComponent.js' ;
5
+
6
+ const TestComponent = ( ) => < div className = 'test-component' > TEST</ div > ;
7
+
8
+ test ( 'asyncComponent: Test placeholder' , t => {
9
+ const Container = asyncComponent ( ( ) => Promise . resolve ( null ) , { placeholder : < TestComponent /> } ) ;
10
+ const tree = shallow ( < Container /> ) ;
11
+
12
+ t . true ( tree . contains ( < TestComponent /> ) ) ;
13
+ } ) ;
14
+
15
+ test ( 'asyncComponent: Test loading module' , t => {
16
+ const promise = Promise . resolve ( TestComponent ) ;
17
+ const Container = asyncComponent ( ( ) => promise ) ;
18
+ const tree = mount ( < Container /> ) ;
19
+
20
+ return promise . then ( ( ) => {
21
+ t . true ( tree . contains ( < TestComponent /> ) ) ;
22
+ } ) ;
23
+ } ) ;
24
+
25
+ test ( 'asyncComponent: Test unmount' , t => {
26
+ const promise = Promise . resolve ( TestComponent ) ;
27
+ const Container = asyncComponent ( ( ) => promise ) ;
28
+ const tree = mount ( < Container /> ) ;
29
+
30
+ tree . unmount ( ) ;
31
+
32
+ return promise . then ( ( ) => {
33
+ t . is ( tree . type ( ) , undefined ) ;
34
+ } ) ;
35
+ } ) ;
Original file line number Diff line number Diff line change
1
+ require ( 'babel-register' )
2
+
3
+ global . document = require ( 'jsdom' ) . jsdom ( '<body></body>' )
4
+ global . window = document . defaultView
5
+ global . navigator = window . navigator
You can’t perform that action at this time.
0 commit comments