I am not sure whether this is an issue or mistake from my side. I have beating my mind around the below issue for a long time and is unable to get past it.
Pseudo-code of React native application:export default class MyProgram extends Component<props, states> {constructor () {// some code}componentDidMount() { // some native/backend call and adding a listener method through nativeEventEmitter }componentDidUpdate() { // few check and same native/backend call}paramsFromBackend() { // listening the JS event and parsing the JS data and hence changing the state of the component }}.
Pseudo-code of Jest Framework:const wrapper = shallowWrapper<MyProgram {...initialProps}>. // This hits constructor and componentDidMount().
// mocked nativeEventEmitter and emitted a fake JS event with fake data (basically replacing the backend data)// paramsFromBackend() gets called and the state changeswrapper.setProps({...oldProps, newProps}). // It hits the componentDidUpdate().
Again mocked nativeEventEmitter and emitted a fake JS event with fake data (basically replacing the backend data)// paramsFromBackend() gets called but the state does not change. Instead it throws the below error:
Method “setState” is meant to be run on 1 node. 3 found instead.
Method “setState” is meant to be run on 1 node. 3 found instead.
Hey guys,
I am not sure whether this is an issue or mistake from my side. I have beating my mind around the below issue for a long time and is unable to get past it.
Pseudo-code of React native application:
export default class MyProgram extends Component<props, states> {
constructor () {// some code}
componentDidMount() { // some native/backend call and adding a listener method through nativeEventEmitter }
componentDidUpdate() { // few check and same native/backend call}
paramsFromBackend() { // listening the JS event and parsing the JS data and hence changing the state of the component }
}
.Pseudo-code of Jest Framework:
const wrapper = shallowWrapper<MyProgram {...initialProps}>. // This hits constructor and componentDidMount()
.// mocked nativeEventEmitter and emitted a fake JS event with fake data (basically replacing the backend data)
// paramsFromBackend() gets called and the state changes
wrapper.setProps({...oldProps, newProps}). // It hits the componentDidUpdate()
.Again mocked nativeEventEmitter and emitted a fake JS event with fake data (basically replacing the backend data)
// paramsFromBackend() gets called but the state does not change. Instead it throws the below error:
Method “setState” is meant to be run on 1 node. 3 found instead.
Method “setState” is meant to be run on 1 node. 3 found instead.
Any help will be appreciated.
P.S. I cannot provide the exact code due to policy.
Thanks, Anirudha