1
1
import injectr from 'injectr' ;
2
- import React from 'react/addons' ;
3
- import testUtils from 'react-shallow-testutils' ;
2
+ import React from 'react' ;
3
+ import { createRenderer } from 'react-addons-test-utils' ;
4
+ import ShallowTestUtils from 'react-shallow-testutils' ;
4
5
5
6
class TestComponent extends React . Component {
6
7
render ( ) {
@@ -13,11 +14,9 @@ class TestComponent extends React.Component {
13
14
describe ( 'Perf component' , function ( ) {
14
15
beforeEach ( function ( ) {
15
16
this . MockReactAddons = {
16
- Perf : {
17
- getLastMeasurements : jasmine . createSpy ( 'Perf.getLastMeasurements' ) ,
18
- printWasted : jasmine . createSpy ( 'Perf.printWasted' ) ,
19
- start : jasmine . createSpy ( 'Perf.start' )
20
- }
17
+ getLastMeasurements : jasmine . createSpy ( 'Perf.getLastMeasurements' ) ,
18
+ printWasted : jasmine . createSpy ( 'Perf.printWasted' ) ,
19
+ start : jasmine . createSpy ( 'Perf.start' )
21
20
} ;
22
21
23
22
this . MockConsole = {
@@ -27,7 +26,7 @@ describe('Perf component', function() {
27
26
this . NODE_ENV = 'development' ;
28
27
29
28
this . makePerf = ( ) => injectr ( '../../src/index.js' , {
30
- 'react/ addons' : Object . assign ( { } , React , { addons : this . MockReactAddons } )
29
+ 'react- addons-perf ' : this . MockReactAddons
31
30
} , {
32
31
console : this . MockConsole ,
33
32
process : { env : { NODE_ENV : this . NODE_ENV } }
@@ -48,10 +47,11 @@ describe('Perf component', function() {
48
47
49
48
it ( 'should render the passed component and pass any props' , function ( ) {
50
49
const Perf = this . perf ( TestComponent ) ;
51
- const renderer = new testUtils . Renderer ( ) ;
52
- const perf = renderer . render ( Perf , null , { test : 1 } ) ;
50
+ const renderer = createRenderer ( ) ;
51
+ renderer . render ( < Perf test = { 1 } /> ) ;
52
+ const perf = renderer . getRenderOutput ( ) ;
53
53
54
- const mockPerfChild = testUtils . findWithType ( perf , TestComponent ) ;
54
+ const mockPerfChild = ShallowTestUtils . findWithType ( perf , TestComponent ) ;
55
55
expect ( mockPerfChild . props . test ) . toEqual ( 1 ) ;
56
56
} ) ;
57
57
@@ -62,34 +62,34 @@ describe('Perf component', function() {
62
62
const perf = new Perf ( ) ;
63
63
perf . componentDidMount ( ) ;
64
64
65
- expect ( this . MockReactAddons . Perf . start ) . toHaveBeenCalled ( ) ;
65
+ expect ( this . MockReactAddons . start ) . toHaveBeenCalled ( ) ;
66
66
} ) ;
67
67
68
68
it ( 'should not print measurements if none are available' , function ( ) {
69
69
const Perf = this . perf ( TestComponent ) ;
70
- this . MockReactAddons . Perf . getLastMeasurements . and . returnValue ( [ ] ) ;
70
+ this . MockReactAddons . getLastMeasurements . and . returnValue ( [ ] ) ;
71
71
72
72
const perf = new Perf ( ) ;
73
73
perf . componentDidMount ( ) ;
74
74
perf . componentDidUpdate ( ) ;
75
75
76
- expect ( this . MockReactAddons . Perf . getLastMeasurements ) . toHaveBeenCalled ( ) ;
77
- expect ( this . MockReactAddons . Perf . printWasted ) . not . toHaveBeenCalled ( ) ;
76
+ expect ( this . MockReactAddons . getLastMeasurements ) . toHaveBeenCalled ( ) ;
77
+ expect ( this . MockReactAddons . printWasted ) . not . toHaveBeenCalled ( ) ;
78
78
expect ( this . MockConsole . log ) . not . toHaveBeenCalled ( ) ;
79
79
} ) ;
80
80
81
81
it ( 'should print measurements if some are available' , function ( ) {
82
82
const Perf = this . perf ( TestComponent ) ;
83
- this . MockReactAddons . Perf . getLastMeasurements . and . returnValue ( [ {
83
+ this . MockReactAddons . getLastMeasurements . and . returnValue ( [ {
84
84
totalTime : 192
85
85
} ] ) ;
86
86
87
87
const perf = new Perf ( ) ;
88
88
perf . componentDidMount ( ) ;
89
89
perf . componentDidUpdate ( ) ;
90
90
91
- expect ( this . MockReactAddons . Perf . getLastMeasurements ) . toHaveBeenCalled ( ) ;
92
- expect ( this . MockReactAddons . Perf . printWasted ) . toHaveBeenCalled ( ) ;
91
+ expect ( this . MockReactAddons . getLastMeasurements ) . toHaveBeenCalled ( ) ;
92
+ expect ( this . MockReactAddons . printWasted ) . toHaveBeenCalled ( ) ;
93
93
expect ( this . MockConsole . log ) . toHaveBeenCalled ( ) ;
94
94
} ) ;
95
95
} ) ;
0 commit comments