Skip to content

Commit 29ab2a0

Browse files
committed
Themr breaks shouldComponentUpdate shallow equal optimization
Add failing test for javivelasco#25
1 parent 3d40e06 commit 29ab2a0

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@
3939
"eslint-plugin-babel": "^3.2.0",
4040
"eslint-plugin-react": "^5.0.1",
4141
"expect": "^1.18.0",
42+
"fbjs": "^0.8.4",
4243
"jsdom": "^8.4.0",
4344
"mocha": "^2.4.5",
4445
"react": "^15.0.1",
4546
"react-addons-test-utils": "^15.0.1",
46-
"rimraf": "^2.5.2"
47+
"react-dom": "^15.3.2",
48+
"rimraf": "^2.5.2",
49+
"sinon": "^1.17.6"
4750
},
4851
"files": [
4952
"lib",

test/components/themr.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import expect from 'expect'
22
import React, { Children, PropTypes, Component } from 'react'
33
import TestUtils from 'react-addons-test-utils'
4+
import sinon from 'sinon'
5+
import { render } from 'react-dom'
6+
import shallowEqual from 'fbjs/lib/shallowEqual'
47
import { themr } from '../../src/index'
58

69
describe('Themr decorator function', () => {
@@ -408,4 +411,33 @@ describe('Themr decorator function', () => {
408411
...bar
409412
})
410413
})
414+
415+
it('should not update theme prop on rerender if nothing changed', () => {
416+
const spy = sinon.stub().returns(<div />)
417+
const div = document.createElement('div')
418+
419+
@themr('Container')
420+
class Container extends Component {
421+
shouldComponentUpdate(nextProps) {
422+
return !shallowEqual(nextProps, this.props)
423+
}
424+
425+
render() {
426+
return spy()
427+
}
428+
}
429+
430+
render(
431+
<Container />,
432+
div
433+
)
434+
435+
render(
436+
<Container />,
437+
div
438+
)
439+
440+
expect(spy.calledOnce).toBe(true)
441+
442+
})
411443
})

0 commit comments

Comments
 (0)