Skip to content

Commit

Permalink
updated the 3rd (and last) comparison test to take into account the c…
Browse files Browse the repository at this point in the history
…omponentWillReceiveProps optimisation introduced before

- since shallowEqual props don't call mapPropsToRequestsToProps again, testing comparison requires props to change such that they are shallow different but deep equal
- also removed the `// TODO: no need to re-render here` comments in these 3 tests because now that they change props such that they are shallowly different the component should in fact re-render
  • Loading branch information
nfcampos authored and Nuno Campos committed Apr 16, 2016
1 parent 856e9e8 commit 49b221b
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions test/components/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,6 @@ describe('React', () => {
expect(fetchSpy.calls.length).toBe(2)

// set BAR again, but will not be refetched
// TODO: no need to re-render here
outerComponent.setFoo('BAR')
expect(renderSpy.calls.length).toBe(5)
setImmediate(() => {
Expand Down Expand Up @@ -1198,7 +1197,6 @@ describe('React', () => {
expect(fetchSpy.calls.length).toBe(2)

// set BAR again, but will not be refetched
// TODO: no need to re-render here
outerComponent.setFoo('BAR')
expect(renderSpy.calls.length).toBe(5)
setImmediate(() => {
Expand All @@ -1217,37 +1215,37 @@ describe('React', () => {
})

it('should compare requests using provided comparison of parent request if then is also provided', (done) => {
const fetchSpy = expect.createSpy(() => ({}))
const fetchSpy = expect.createSpy()
fetchSpies.push(fetchSpy)

const renderSpy = expect.createSpy(() => ({}))

function render() {
renderSpy()
return <Passthrough/>
}
const renderSpy = expect.createSpy()

@connect(({ foo }) => ({
testFetch: {
url: '/resource-without-foo',
comparison: foo,
comparison: foo.FOO,
then: (v, m) => ({ value: v, meta: m })
}
}))
class WithProps extends Component {
render() {
return render(this.props)
renderSpy()
return <Passthrough {...this.props} />
}
}

class OuterComponent extends Component {
constructor() {
super()
this.state = { foo: 'FOO' }
this.state = {
foo: {
FOO: 'FOO'
}
}
}

setFoo(foo) {
this.setState({ foo })
setFoo(FOO) {
this.setState({ foo: { FOO } })
}

render() {
Expand Down Expand Up @@ -1275,7 +1273,6 @@ describe('React', () => {
expect(fetchSpy.calls.length).toBe(2)

// set BAR again, but will not be refetched
// TODO: no need to re-render here
outerComponent.setFoo('BAR')
expect(renderSpy.calls.length).toBe(5)
setImmediate(() => {
Expand Down

0 comments on commit 49b221b

Please sign in to comment.