From 7fcbb35d065ccc3b6bfe740a22ef693cb945e672 Mon Sep 17 00:00:00 2001 From: Angelika Tyborska Date: Fri, 16 Mar 2018 11:42:58 +0100 Subject: [PATCH] [Tests] Extend findWhere null nodes test Test case for issue #1566 without a fix. --- .../test/ReactWrapper-spec.jsx | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx index 38ebca1e4..f4f70b243 100644 --- a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx +++ b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx @@ -1105,21 +1105,56 @@ describeWithDOM('mount', () => { }); }); - it('should not pass in null or false nodes', () => { + it('does not pass in null or false nodes', () => { const wrapper = mount(( -
+
+
foo bar
{null} {false} -
+
)); const stub = sinon.stub(); - stub.returns(true); - const spy = sinon.spy(stub); - wrapper.findWhere(spy); - expect(spy.callCount).to.equal(2); + wrapper.findWhere(stub); + + const passedNodes = stub.getCalls().map(({ args: [firstArg] }) => firstArg); + const hasDOMNodes = passedNodes.map(n => [n.debug(), n.getDOMNode() && true]); + const expected = [ + [wrapper.debug(), true], // root + ['
', true], // first div + ['
\n foo bar\n
', true], // second div + ['foo bar', null], // second div's contents + ]; + expect(hasDOMNodes).to.eql(expected); + + // the root, plus the 2 renderable children, plus the grandchild text + expect(stub).to.have.property('callCount', 4); }); + it('allows `.text()` to be called on text nodes', () => { + const wrapper = mount(( +
+
+
foo bar
+ {null} + {false} +
+ )); + + const stub = sinon.stub(); + wrapper.findWhere(stub); + + const passedNodes = stub.getCalls().map(({ args: [firstArg] }) => firstArg); + + const textContents = passedNodes.map(n => [n.debug(), n.text()]); + const expected = [ + [wrapper.debug(), 'foo bar'], // root + ['
', ''], // first div + ['
\n foo bar\n
', 'foo bar'], // second div + ['foo bar', null], // second div's contents + ]; + expect(textContents).to.eql(expected); + }); }); describe('.setProps(newProps[, callback])', () => {