diff options
Diffstat (limited to 'thirdparty/preact/test/browser/context.js')
-rw-r--r-- | thirdparty/preact/test/browser/context.js | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/thirdparty/preact/test/browser/context.js b/thirdparty/preact/test/browser/context.js index e62a948a4..ed5f81471 100644 --- a/thirdparty/preact/test/browser/context.js +++ b/thirdparty/preact/test/browser/context.js @@ -1,6 +1,8 @@ import { h, render, Component } from '../../src/preact'; /** @jsx h */ +const CHILDREN_MATCHER = sinon.match( v => v==null || Array.isArray(v) && !v.length , '[empty children]'); + describe('context', () => { let scratch; @@ -57,18 +59,19 @@ describe('context', () => { expect(Outer.prototype.getChildContext).to.have.been.calledOnce; // initial render does not invoke anything but render(): - expect(Inner.prototype.render).to.have.been.calledWith({}, {}, CONTEXT); + expect(Inner.prototype.render).to.have.been.calledWith({ children:CHILDREN_MATCHER }, {}, CONTEXT); CONTEXT.foo = 'bar'; render(<Outer {...PROPS} />, scratch, scratch.lastChild); expect(Outer.prototype.getChildContext).to.have.been.calledTwice; - expect(Inner.prototype.shouldComponentUpdate).to.have.been.calledOnce.and.calledWith(PROPS, {}, CONTEXT); - expect(Inner.prototype.componentWillReceiveProps).to.have.been.calledWith(PROPS, CONTEXT); - expect(Inner.prototype.componentWillUpdate).to.have.been.calledWith(PROPS, {}); - expect(Inner.prototype.componentDidUpdate).to.have.been.calledWith({}, {}); - expect(Inner.prototype.render).to.have.been.calledWith(PROPS, {}, CONTEXT); + let props = { children: CHILDREN_MATCHER, ...PROPS }; + expect(Inner.prototype.shouldComponentUpdate).to.have.been.calledOnce.and.calledWith(props, {}, CONTEXT); + expect(Inner.prototype.componentWillReceiveProps).to.have.been.calledWith(props, CONTEXT); + expect(Inner.prototype.componentWillUpdate).to.have.been.calledWith(props, {}); + expect(Inner.prototype.componentDidUpdate).to.have.been.calledWith({ children:CHILDREN_MATCHER }, {}); + expect(Inner.prototype.render).to.have.been.calledWith(props, {}, CONTEXT); /* Future: @@ -115,18 +118,19 @@ describe('context', () => { expect(Outer.prototype.getChildContext).to.have.been.calledOnce; // initial render does not invoke anything but render(): - expect(Inner.prototype.render).to.have.been.calledWith({}, {}, CONTEXT); + expect(Inner.prototype.render).to.have.been.calledWith({ children: CHILDREN_MATCHER }, {}, CONTEXT); CONTEXT.foo = 'bar'; render(<Outer {...PROPS} />, scratch, scratch.lastChild); expect(Outer.prototype.getChildContext).to.have.been.calledTwice; - expect(Inner.prototype.shouldComponentUpdate).to.have.been.calledOnce.and.calledWith(PROPS, {}, CONTEXT); - expect(Inner.prototype.componentWillReceiveProps).to.have.been.calledWith(PROPS, CONTEXT); - expect(Inner.prototype.componentWillUpdate).to.have.been.calledWith(PROPS, {}); - expect(Inner.prototype.componentDidUpdate).to.have.been.calledWith({}, {}); - expect(Inner.prototype.render).to.have.been.calledWith(PROPS, {}, CONTEXT); + let props = { children: CHILDREN_MATCHER, ...PROPS }; + expect(Inner.prototype.shouldComponentUpdate).to.have.been.calledOnce.and.calledWith(props, {}, CONTEXT); + expect(Inner.prototype.componentWillReceiveProps).to.have.been.calledWith(props, CONTEXT); + expect(Inner.prototype.componentWillUpdate).to.have.been.calledWith(props, {}); + expect(Inner.prototype.componentDidUpdate).to.have.been.calledWith({ children: CHILDREN_MATCHER }, {}); + expect(Inner.prototype.render).to.have.been.calledWith(props, {}, CONTEXT); // make sure render() could make use of context.a expect(Inner.prototype.render).to.have.returned(sinon.match({ children:['a'] })); @@ -164,7 +168,7 @@ describe('context', () => { render(<Outer />, scratch); - expect(Inner.prototype.render).to.have.been.calledWith({}, {}, { outerContext }); - expect(InnerMost.prototype.render).to.have.been.calledWith({}, {}, { outerContext, innerContext }); + expect(Inner.prototype.render).to.have.been.calledWith({ children: CHILDREN_MATCHER }, {}, { outerContext }); + expect(InnerMost.prototype.render).to.have.been.calledWith({ children: CHILDREN_MATCHER }, {}, { outerContext, innerContext }); }); }); |