enzymejs/chai-enzyme

.not.to.exist assertion doesn't work with mount()

Closed this issue · 0 comments

chai-enzyme version: 0.4.0
enzyme version: 1.5.0

I'm running into an issue where asserting that an empty wrapper is not present() works in components rendered with shallow but not with mount. Minimal repro:

const shallowWrapper = shallow(<div/>)
expect(shallowWrapper.find('#notfound')).not.to.exist // ✓
const mountWrapper = mount(<div/>)
expect(mountWrapper.find('#notfound')).not.to.exist // ✗

The last call there blows up with this stack trace:

Error: This method is only meant to be run on single node. 0 found instead.
  at ReactWrapper.single (node_modules/enzyme/build/ReactWrapper.js:1065:17)
  at new ReactTestWrapper (node_modules/chai-enzyme/build/ReactTestWrapper.js:32:30)
  at wrap (node_modules/chai-enzyme/build/wrap.js:30:12)
  at Assertion.<anonymous> (node_modules/chai-enzyme/build/ChaiWrapper.js:136:42)
  at Assertion.Object.defineProperty.get (node_modules/chai/lib/chai/utils/overwriteProperty.js:50:37)
  at Context.<anonymous> (tests/chai-enzyme-repro.jsx:15:57)