From b0d35c7290339875284a4ecca223c1c83fe37344 Mon Sep 17 00:00:00 2001 From: Neil de Carteret Date: Mon, 20 Feb 2017 17:50:16 +0000 Subject: [PATCH] handle `.exactly(0)` (#152) --- src/assertions/descendants.js | 2 +- test/exactly.test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/assertions/descendants.js b/src/assertions/descendants.js index ec6a20f..1899c80 100644 --- a/src/assertions/descendants.js +++ b/src/assertions/descendants.js @@ -1,7 +1,7 @@ export default function descendants ({ wrapper, markup, arg1, sig, flag }) { const exactlyCount = flag(this, 'exactlyCount') - if (exactlyCount) { + if (exactlyCount || exactlyCount === 0) { const descendantCount = wrapper.getDescendantsCount(arg1) this.assert( diff --git a/test/exactly.test.js b/test/exactly.test.js index e6878b2..7a1d5b3 100644 --- a/test/exactly.test.js +++ b/test/exactly.test.js @@ -29,6 +29,10 @@ describe('#exactly', () => { expect(wrapper).to.have.exactly(8).descendants('.multiple') }) + it('passes when the the expected is 0 and there are none', (wrapper) => { + expect(wrapper).to.have.exactly(0).descendants('#root1') + }) + it('passes negated when the actual does not match the expected', (wrapper) => { expect(wrapper).to.not.have.exactly(3).descendants('#root1') expect(wrapper.find('#child')).to.not.have.exactly(5).descendants('#last1') @@ -47,5 +51,11 @@ describe('#exactly', () => { expect(wrapper).to.not.have.exactly(8).descendants('.multiple') }).to.throw("not to have 8 descendants '.multiple'") }) + + it('fails when the the expected is 0 and there are some', (wrapper) => { + expect(() => { + expect(wrapper).to.have.exactly(0).descendants('#root') + }).to.throw("to have 0 descendants '#root'") + }) }) })