Go Pro Sign Up Login
0 days 0 hrs 0 min 0 sec

Summer Sale

50% off Level Up Pro until you unsubscribe.
Get access to ALL 128 courses on Level Up Tutorials

This is your last chance to get Level Up Pro for $145/year.

or Learn More
Moon Moon

Buy Now and unlock this series

$

39

.99

yours forever

Become a Pro and unlock everything

$

24

.99

per month

Mocking Modules

In this video, we are going to continue learning about mock functions through mocking modules.

Downloads

Become a pro to download code and videos

Comments

Brett

9 months ago [edited]

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

EDIT: so sorry about all the comments. The button seemed like it was not working and when I reloaded the page, there were tons of them. Can't delete them. Sorry about that.

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

Brett

9 months ago

Near the end of the video when he has expect(add).toBeCalledTImes(1), is that checking whether the mock add function was called once or is it checking whether the real add function in ./add was called?

David T

about 2 years ago

Scott, can you add a lesson to this tutorial of how to do mocking with class methods?

I am using a class to do my api requests.

Hello There!

over 2 years ago [edited]

I followed along and got this error.

TypeError: Cannot read property 'add' of undefined

App.test.js

import { total } from "./App"; import { add } from "./add";

jest.mock('./add', () => { add: jest.fn(() => 25) })

test('total ', () => { expect(total(5, 20)).toBe("$25") expect(add).toHaveBeenCalledTimes(1)

add.mockImplementation(() => 30)

expect(total(5, 25)).toBe("$30")
expect(add).toHaveBeenCalledTimes(2)

})

App.JS

import { add } from "./add"

export const total = (shipping, subTotal) => { return "$" + add(shipping, subTotal) }

add.js

export const add = (x,y) => { return x + y }

SOLVED I forgot to a parenthesis on

Ausar McGruder

over 2 years ago

@ninja I was having issues too. Just code along..you'll get errors that he isn't getting because he doesn't actually save his changes around 8:50. It starts to make sense around 9:30.

J

over 2 years ago

what about mocking default exports?

User avatar

Dallas

about 3 years ago

@ninja Hey ninja, what part are you specifically having trouble with?

ninja

about 3 years ago [edited]

In #5 Mocking Modules, I am having a hard time following this part of the tutorial. There is a lot of back and forth with explanation and im not sure why you are doing what you are doing. By the time I get to 8.5 min, I am totally lost.

Want to join the conversation?

Become a Pro member today!