I have a class that looks like:
class Dummy {
constructor(props) {
super(props)
this.dummyObj = 'dummy'
}
}
and I want to access this.dummyObj and change its value to say: 'hi'
is this possible with Jest/Enzyme?
thanks!
You can do that by making an instance:
import React from 'react';
import Enzyme, { shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() });
describe('<YourComponent />', () => {
const wrapper = shallow(
<YourComponent
{...yourProps}
/>
);
const instance = wrapper.instance();
it('Should have correct dummyObj value', () => {
expect(instance.dummyObj).toBe('dummy');
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With