Skip to content

Commit

Permalink
handle .exactly(0) (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
n3dst4 authored and ayrton committed Feb 20, 2017
1 parent 74e4b16 commit b0d35c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/assertions/descendants.js
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
10 changes: 10 additions & 0 deletions test/exactly.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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'")
})
})
})

0 comments on commit b0d35c7

Please sign in to comment.