Skip to content

Commit

Permalink
Update "Don't mock in Jest"
Browse files Browse the repository at this point in the history
Update examples to include correct `renderWithProviders()` test helper.
  • Loading branch information
antgonzales committed Jun 4, 2024
1 parent a51f82e commit fd2db71
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions _posts/2024-06-03-dont-mock-in-jest.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description: "Discover why avoiding mocks in Jest enhances testing. Learn
strategies for resilient, standards-based tests that improve code
maintainability and reliability."
date: 2024-06-03
last_modified_at: 2024-06-04
---

Jest revolutionized front-end testing when it was released in 2014 by
Expand Down Expand Up @@ -77,7 +78,7 @@ jest.mock('react-router-dom', () => ({

describe('<ComponentWithNavigation />', () => {
it('provides a link to return to the dashboard', async () => {
render(<ComponentWithNavigation />)
renderWithProviders(<ComponentWithNavigation />)
const link = screen.getByRole(link, {name: 'Go to Home'});
fireEvent.click(link);
// ❌ Testing implementation details
Expand Down Expand Up @@ -111,7 +112,7 @@ import React from 'react';

describe('<ComponentWithNavigation />', () => {
it('provides a link to return to the dashboard', async () => {
render(<ComponentWithNavigation />)
renderWithProviders(<ComponentWithNavigation />)
const link = screen.getByRole(link, {name: 'Go to Home'});
// ✅ Checking the link element render
expect(link.href).toBe('/');
Expand Down

0 comments on commit fd2db71

Please sign in to comment.