Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 1b5df3e

Browse files
committed
Merge pull request #2 from sheepsteak/react-0-14
Updated to React 0.14
2 parents 0961d53 + a7fe6cb commit 1b5df3e

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@
3030
"eslint-plugin-react": "^2.7.0",
3131
"injectr": "^0.5.1",
3232
"jasmine": "^2.3.1",
33-
"react-shallow-testutils": "^0.2.1"
33+
"react": "0.14.3",
34+
"react-addons-perf": "0.14.0",
35+
"react-addons-test-utils": "^0.14.0",
36+
"react-shallow-testutils": "^0.7.1"
3437
},
3538
"peerDependencies": {
36-
"react": "^0.13.3"
39+
"react": "^0.14.0",
40+
"react-addons-perf": "^0.14.0"
3741
}
3842
}

specs/index-spec.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
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';
45

56
class TestComponent extends React.Component {
67
render() {
@@ -13,11 +14,9 @@ class TestComponent extends React.Component {
1314
describe('Perf component', function() {
1415
beforeEach(function() {
1516
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')
2120
};
2221

2322
this.MockConsole = {
@@ -27,7 +26,7 @@ describe('Perf component', function() {
2726
this.NODE_ENV = 'development';
2827

2928
this.makePerf = () => injectr('../../src/index.js', {
30-
'react/addons': Object.assign({}, React, {addons: this.MockReactAddons})
29+
'react-addons-perf': this.MockReactAddons
3130
}, {
3231
console: this.MockConsole,
3332
process: {env: {NODE_ENV: this.NODE_ENV}}
@@ -48,10 +47,11 @@ describe('Perf component', function() {
4847

4948
it('should render the passed component and pass any props', function() {
5049
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();
5353

54-
const mockPerfChild = testUtils.findWithType(perf, TestComponent);
54+
const mockPerfChild = ShallowTestUtils.findWithType(perf, TestComponent);
5555
expect(mockPerfChild.props.test).toEqual(1);
5656
});
5757

@@ -62,34 +62,34 @@ describe('Perf component', function() {
6262
const perf = new Perf();
6363
perf.componentDidMount();
6464

65-
expect(this.MockReactAddons.Perf.start).toHaveBeenCalled();
65+
expect(this.MockReactAddons.start).toHaveBeenCalled();
6666
});
6767

6868
it('should not print measurements if none are available', function() {
6969
const Perf = this.perf(TestComponent);
70-
this.MockReactAddons.Perf.getLastMeasurements.and.returnValue([]);
70+
this.MockReactAddons.getLastMeasurements.and.returnValue([]);
7171

7272
const perf = new Perf();
7373
perf.componentDidMount();
7474
perf.componentDidUpdate();
7575

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();
7878
expect(this.MockConsole.log).not.toHaveBeenCalled();
7979
});
8080

8181
it('should print measurements if some are available', function() {
8282
const Perf = this.perf(TestComponent);
83-
this.MockReactAddons.Perf.getLastMeasurements.and.returnValue([{
83+
this.MockReactAddons.getLastMeasurements.and.returnValue([{
8484
totalTime: 192
8585
}]);
8686

8787
const perf = new Perf();
8888
perf.componentDidMount();
8989
perf.componentDidUpdate();
9090

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();
9393
expect(this.MockConsole.log).toHaveBeenCalled();
9494
});
9595
});

src/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React from 'react/addons';
1+
import React from 'react';
2+
import ReactPerf from 'react-addons-perf';
23

34
/**
45
* Wraps the passed in `Component` in a higher-order component. It can then
@@ -16,19 +17,19 @@ export default function perf(Component) {
1617

1718
return class Perf extends React.Component {
1819
componentDidMount() {
19-
React.addons.Perf.start();
20+
ReactPerf.start();
2021
}
2122
componentDidUpdate() {
22-
const measurements = React.addons.Perf.getLastMeasurements();
23+
const measurements = ReactPerf.getLastMeasurements();
2324

2425
if (measurements.length > 0) {
2526
this.totalRenders = (this.totalRenders || 0) + 1;
2627
this.totalTime = (this.totalTime || 0) + measurements[0].totalTime;
2728

2829
console.log(`Average: ${this.totalTime / this.totalRenders} over ${this.totalRenders} renders.`);
2930

30-
React.addons.Perf.printWasted(measurements);
31-
React.addons.Perf.start();
31+
ReactPerf.printWasted(measurements);
32+
ReactPerf.start();
3233
}
3334
}
3435
render() {

0 commit comments

Comments
 (0)