-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Component methods not found (undefined) in instance() #1045
Comments
Because the instance there is the connected component wrapper which lacks those methods. Try .dive().instance() |
@ljharb Thanks for the quick reply, however I've changed my test file into this code, and it stills give me undefined. const wrapper = shallow(<Calendar store={mockStore()} />);
const instance = wrapper.dive().instance();
console.log(instance.normalizeEvents); |
@denichodev ah, you're using two HOCs - connect and withRouter. So, you'll need |
I have the same problem without a HoC. Prepared minimal reproducible code fragment: class TestComponent extends React.Component {
render() {
return (<View/>)
}
}
it("has an instance", () => {
const wrapper = shallow(<TestComponent/>)
const inst = wrapper.instance();
expect(inst).toBeTruthy();
}) This code ends with:
Edit: |
Your minimal repro case should pass; and your error is from different code. Can you please provide the exact code that's erroring? |
But it is the exact code that's erroring :P /* instance.test.js */
import {shallow} from "enzyme"
import * as React from "react"
import {View} from "react-native-mock"
class TestComponent extends React.Component {
render() {
return (<View/>)
}
}
it("is an instance", () => {
const wrapper = shallow(<TestComponent/>)
const inst = wrapper.instance();
expect(inst).toBeTruthy();
})
|
@wnadurski |
According to Jest's documentation of the test('the best flavor is grapefruit', () => {
expect(bestLaCroixFlavor()).toBe('grapefruit');
}); which results in error message:
But yes, I know it's very strange. It had worked before, and just stopped without a reason :P |
Weird; we use chai with jest, so I've never seen that error. @wnadurski At any rate, what does |
@ljharb |
Wait, |
Yup, I'm using React |
@denichodev, happy to reopen if #1045 (comment) doesn't solve your issue. |
Hi, so apparently I can't get the methods of a React component using
wrapper.instance().normalizeEvents([mockArray])
This is what my code looks like, I have been looking for answers anywhere but still, no luck.
Calendar.js
Calendar.test.js
It shows up an error on my jest test, as
TypeError: wrapper.normalizeEvents is not a function
Is there something wrong with the code or?
EDIT:
version lists
The text was updated successfully, but these errors were encountered: