Buy Now and unlock this series
$
39
.99
yours forever
$
39
.99
Become a Pro and unlock everything
$
24
.99
per month
$
24
.99
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
React Testing For Beginners
24 videos
Course Instructor
Scott Tolinski
- React Testing for Beginners
1M15S - Introduction To Testing With Jest
11M59S - Jest Explained
8M37S - Writing Unit Tests With Jest
13M12S - Writing Integration Tests
8M2S - Mock Functions & Why
9M16S - Mocking Modules
14M12S - Introduction To React Testing
6M51S - React Testing Library & Debug
13M11S - Testing With Test Ids
8M25S - Events In React Testing Library
10M47S - Integration Testing In React & Cleanup
17M47S - Snapshot Testing 101
8M12S - Spying & Mocking Functions in React
9M50S - Form Events With Controlled Inputs
11M42S - Testing For Errors & Global Mocks
7M45S - Negative Assertions & Testing With React Router
9M33S - What To Test
9M17S - Mocking Fetch
9M53S - Mocking Fetch Part 2 Async Tests & Working With Data
12M49S - Testing Loading States & More Pitfalls
18M48S - Refactoring With Tests
9M5S - Code Coverage
4M31S - Where To Go From Here
3M21S
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)
})
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?
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!