Jest Unit Test in Ionic App

I am trying to test my ionic app with Jest instead of traditional Jasmine and Karma. I can run a simple test, for example

expect(1).toEqual(1)

and the test passed without problems.

The problem I encountered is testing services. I have something like

expect(CalculatorService).toBeDefined();

and the test result will be transmitted, indicating that the service is defined. However, when I tried to call the CalculatorService method

expect(CalculatorService.add(1,1).toEqual(2)

leads to

"TypeError: CalculatorService.add is not a function"

I know that with Jasmine and Karma we need to introduce a service. But I do not know what is equivalent to Jest.

Can someone shed some light?

+4
source share

No one has answered this question yet.

Source: https://habr.com/ru/post/1649111/


All Articles