Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6211

expected spyOn function to be called Jest

$
0
0

im currently trying to test the methods that i have created and the methods in my if statement are not being called. and im completely at a loss. I am new too jest though so im sure its something simple im missing.

 describe('isSingleScreen', () => {    beforeEach(() => {      jest.clearAllMocks();      jest.spyOn(utilMethods, 'isDualScreen').mockReturnValue(true);    });    it('autoScreenAdd', () => {      // Arrange      const singleScreenAddSpy = jest.spyOn(        singleScreenMethods,'singleScreenAdd'      );      const dualScreenAddSpy = jest.spyOn(dualScreenMethods, 'dualScreenAdd');      // Act      utilMethods.autoScreenAdd({});      // Assert      expect(singleScreenAddSpy).toBeCalledTimes(0);      expect(dualScreenAddSpy).toBeCalled();      expect(dualScreenAddSpy).toBeCalledTimes(1);    });  });

export const isDualScreen = (): boolean => {  return Dimensions.get('window').width > 1000 ? true : false;};export const autoScreenAdd = (element: IDualComponent) => {  if (isDualScreen()) {    dualScreenAdd(element);  } else {    singleScreenAdd(element);  }};

this is the error i receive

    expect(jest.fn()).toBeCalledTimes(expected)    Expected number of calls: 0    Received number of calls: 1      30 |       // Assert      31 |       expect(autoScreenAddSpy).toBeCalled();> 32 |       expect(singleScreenAddSpy).toBeCalledTimes(0);         |                                  ^      33 |       expect(dualScreenAddSpy).toBeCalled();      34 |       expect(dualScreenAddSpy).toBeCalledTimes(1);      35 |     });

Viewing all articles
Browse latest Browse all 6211

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>