Cult of the Machines

A little iPad in the corner asked me,“what do you do for a living?” I typed,“partnerships”. It did not compute. I retyped,“sales”. It made me feel less bad about myself (suckit, computer scientists!)…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Problem

I used Jest to mock the function for unit test on the nodeJS application. I ran into a situation that the toHaveBeenCalledTimes actual value not correct for the second ‘it’ test case. The called times count was one more than the expected value.

Therefore, I though that it may accumulate the previous toHaveBeenCalledTimes count for the first test case. Then I found out that I didn’t call mockReset for this newly used method.

I added the function.mockReset() in the afterEach hook and the count was matched after. This way will reset toHaveBeenCalledTimes for the mock function after each test case.

Add a comment

Related posts:

How I landed on Medium.

After giving birth to my baby girl and moving to England, it was time I did something apart from house making. Being a housemaker is great, but that is not everything I want. But for a long time, I…

How to Bring Abstract Concepts to Life for Readers

The most successful books at the Pragmatic Bookshelf do a great job of explaining complex topics. So what’s the magic? Part of the not-so-secret is that we get to building and doing stuff right away…

20 Reasons Why People Fail to Succeed in Life

Everyone wants to be successful. But most people do not know why they are not successful yet. They just blindly follow the self-help guide without success.