Unable to update state after specific scenario using jest cucumber react native test cases

21 views Asked by At

I am unable to update loading state after "test 1" step.

at first it is being updated loading becomes true, in second scenario it becomes true but in "test 2" to scenario it still remains false

also when ever I at new step before "test 1" step it will stop updating in "test 1" also.

defineFeature(feature, (test) => {
  jest.useFakeTimers();
  beforeEach(() => {
    jest.resetModules();
    jest.doMock("react-native", () => ({ Platform: { OS: "android" } }));
    jest.spyOn(helpers, "getOS").mockImplementation(() => "android");
  });
 test("User navigates to scheduling", ({ given, when, then, and }) => {
    let schedulingBlock: ShallowWrapper;
    let instance: Scheduling;

    given("I am a User loading scheduling", () => {
      schedulingBlock = shallow(<Scheduling {...screenProps} />);
    });

    when("I navigate to the scheduling", () => {
      instance = schedulingBlock.instance() as Scheduling;
      instance.setState({loading:true},()=>{
        console.log("LOADING:",instance.state.loading)
      })
    });
    
    then("test 1",()=>{
      instance.setState({loading:false},()=>{
        console.log("LOADING Test 1:",instance.state.loading, instance)
      })
    })
    then("test 2",()=>{
      instance.setState({loading:true},()=>{
        console.log("LOADING Test 2:",instance.state.loading, instance)
      })
    })
});
});

I tried updating state by creating function which toggle the loading state in Component and called it but when ever I cross one then function it stop updating and holds the state updated in first then step.

I want to state to be updated by function or in direct manner by calling instance.setState after the first then also and state should change accordingly

0

There are 0 answers