I have been following an example from the doc:
https://github.com/airbnb/enzyme/blob/v2.5.1/docs/api/ShallowWrapper/forEach.md
My code is:
import { shallow } from 'enzyme';
import React from 'react';
const wrapper = shallow(
<div>
<div className="foo bax" />
<div className="foo bar" />
<div className="foo baz" />
</div>
);
describe('<Alert />', () => {
it('should render a <div> tag without a theme', () => {
wrapper.find('.foo').forEach(function (node){
expect(node.hasClass('foo')).toEqual(true);
});
});
});
This returns TypeError: Cannot read property 'equal' of undefined
If I replace to.equal() by toEqual the test passes.
Why is that the case?
That's because you are using a different test runner. the .to.equal is from mocha. You are likely using jest or jasmine. This is not an enzyme issue. I'm going to close it out. Let us know if there is a way the docs could be clearer.
Hey, I had the same issue. I managed to solve it by changing to.equal into toEqual. I wanted to leave this comment, however, to raise a question about the docs.
I may be reading the docs wrong, but from this page, there is no indication that it is mocha or jest specific. Is there a separate API guide for each framework?
All of our examples use chai, which works with mocha or jest. Jest has their own built in matchers, which are based in jasmine, but we don't use those. import { expect } from 'chai' in each test file should do it.
@redixhumayun I also got it, it will be the version of the documentation (I was reading the documentation in the same place as you)
Most helpful comment
Hey, I had the same issue. I managed to solve it by changing to.equal into toEqual. I wanted to leave this comment, however, to raise a question about the docs.
I may be reading the docs wrong, but from this page, there is no indication that it is mocha or jest specific. Is there a separate API guide for each framework?