Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,4 @@ yarn.lock | |
|
||
# generated files | ||
index.js | ||
react.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const equal: (a: any, b: any) => boolean; | ||
export = equal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const equal: (a: any, b: any) => boolean; | ||
export = equal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const equal: (a: any, b: any) => boolean; | ||
export = equal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const sinon = require('sinon'); | ||
const React = require('react'); | ||
const ReactTestRenderer = require('react-test-renderer'); | ||
|
||
const equal1 = require('../es6/react'); | ||
const equal2 = require('../react'); | ||
|
||
const run = equal => { | ||
class ChildWithShouldComponentUpdate extends React.Component { | ||
shouldComponentUpdate(nextProps) { | ||
// this.props.children is a h1 with a circular reference to its owner, Container | ||
return !equal(this.props, nextProps); | ||
} | ||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
class Container extends React.Component { | ||
render() { | ||
return React.createElement(ChildWithShouldComponentUpdate, { | ||
children: [ | ||
React.createElement('h1', this.props.title || ''), | ||
React.createElement('h2', this.props.subtitle || '') | ||
] | ||
}); | ||
} | ||
} | ||
|
||
describe('advanced', () => { | ||
let sandbox; | ||
let warnStub; | ||
let childRenderSpy; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
warnStub = sandbox.stub(console, 'warn'); | ||
childRenderSpy = sandbox.spy(ChildWithShouldComponentUpdate.prototype, 'render'); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('React', () => { | ||
describe('element (with circular references)', () => { | ||
it('compares without warning or errors', () => { | ||
const testRenderer = ReactTestRenderer.create(React.createElement(Container)); | ||
testRenderer.update(React.createElement(Container)); | ||
assert.strictEqual(warnStub.callCount, 0); | ||
}); | ||
it('elements of same type and props are equal', () => { | ||
const testRenderer = ReactTestRenderer.create(React.createElement(Container)); | ||
testRenderer.update(React.createElement(Container)); | ||
assert.strictEqual(childRenderSpy.callCount, 1); | ||
}); | ||
it('elements of same type with different props are not equal', () => { | ||
const testRenderer = ReactTestRenderer.create(React.createElement(Container)); | ||
testRenderer.update(React.createElement(Container, { title: 'New' })); | ||
assert.strictEqual(childRenderSpy.callCount, 2); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
run(equal1); | ||
run(equal2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters