joetidee / enzyme-react-intl

A complimentary wrapper function for use with Enzyme, when testing React components that rely on react-intl
MIT License
45 stars 15 forks source link

dive().state() returns null when the component is initiated with shallowWithIntl #36

Open tridhe opened 3 years ago

tridhe commented 3 years ago

I am using shallowwithintl to wrap my component. Then I am calling the function changeState(mockedEvent, mockedEvent2) which is used to set the state. Then I am console logging the updated state.

const component = shallowWithIntl(<ExampleComponent/>);
const mockedEvent = { currentTarget: { id: 111, value: 111} };
const mockedEvent2 = { key: 111};
component.dive().instance().changeState(mockedEvent, mockedEvent2);
console.log(component.dive().state())

Ideally component.dive().state() should return the state but it is returning null values. The output looks like this:

{  id: null,
    value: null,
    key: null 
 }

Please let me know if I am missing something here.

tridhe commented 3 years ago

Similar issues are reported below but no fix given: https://github.com/joetidee/enzyme-react-intl/issues/21 https://github.com/joetidee/enzyme-react-intl/issues/2 https://github.com/joetidee/enzyme-react-intl/issues/14