question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue using chai-enzyme alongside chai-jquery

See original GitHub issue

The root of the problem appears to stem from the fact that chai-jquery uses checked as a property:

expect($(node)).to.be.checked;

While chai-enzyme implements it as an assertion method:

expect(wrapper).to.be.checked();

If I call chai.use with chai-jquery first, chai-enzyme chokes while trying to add the checked assertion (chaiWrapper.addAssertion(checked, 'checked')): Uncaught TypeError: Cannot read property 'is' of undefined

If I call chai.use with chai-enzyme first, chai-jquery overwrites the checked assertion as a property.

Any ideas on how to make them play nice together?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
keithamuscommented, Apr 26, 2016

@ljharb I don’t want to hijack this thread, so I’ll just say we have an issue (https://github.com/chaijs/chai/issues/585) which details what the new plugin interface will look like. Plugins will be abstracted away from decisions like property based assertions, and it will be determined by interface.

0reactions
eugenet8kcommented, Dec 8, 2017

Hi guys, it’s been a while and I guess the chai plugin system wasn’t updated yet. But, can anyone post some feasible solution or workaround or hack to solve this issue meanwhile?

In my case, some of my modules have unit tests for jQuery based UI and another for React based, so if I only get an idea how to initialize chai per module then I would use chai-jquery and chai-enzyme independently. Although it seems if I call chai.use once the plugin stays there forever until I restart the browser. I couldn’t figure out a way to initialize chai within a module scope. Is there a way to do so?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the benefit of enzyme in comparison to chai-jquery #546
I'm using redux with react in my app, so if I try to test a component which has access to redux store with...
Read more >
Unit Test d3v4 zoom behavior in React with Chai
Using d3v4, react and chai (chai-enzyme, chai-jquery) for unit testing. So I have a zoom behavior attached to my graph.
Read more >
the Different Testing Tools (chai, mocha, enzyme, jest) - Leanne
A unit testing framework developed by Facebook for ReactJS project. Use Jest to capture snapshots of React components for certain time with props...
Read more >
Chai-jQuery - Chai Assertion Library
Chai is a BDD / TDD assertion library for [node](http://nodejs.org) and the browser that can be delightfully paired with any javascript testing framework....
Read more >
How to test React with Mocha, Chai & Enzyme - Robin Wieruch
Learn how to test your React application with Mocha, Chai & Enzyme. Mocha will be used as a test runner, Chai as testing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found