Cannot read property 'have' of undefined
morijenab opened this issue ยท 0 comments
morijenab commented
Hello
Thanks for your awesome work. Its really useful and cool that we can test ower CSS Style with your code ๐
I tried to implement your sample code but faced with this error
Cannot read property 'have' of undefined
here is my test suite :
import React from "react";
import Enzyme from "enzyme";
import Adapter from "enzyme-adapter-react-16";
import chai from "chai";
import chaiEnzyme from "chai-enzyme";
import { mount } from "enzyme";
Enzyme.configure({ adapter: new Adapter() });
chai.use(chaiEnzyme()); // Note the invocation at the end
class Fixture extends React.Component {
render() {
return (
<div className="root top">
<span className="child bottom">test</span>
</div>
);
}
}
const wrapper = mount(<Fixture />); // mount/render/shallow when applicable
expect(wrapper.find("span")).to.have.className("child");
expect(wrapper.find("span")).to.not.have.className("root");
and these are the packages that I'm using:
"chai": "^4.2.0",
"chai-enzyme": "^1.0.0-beta.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.3",
Did I miss something ๐
UPDate:
I guess the problem is expect !
if I import 'expect' from jest the error is :
Cannot read property 'have' of undefined
in the case import from 'chai-enzyme'
_TypeError: (0 , chaiEnzyme.expect) is not a function