Skip to content

Commit 8e556d7

Browse files
committed
update readme
1 parent a0748fa commit 8e556d7

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

05-testing/01-react/05-real-project/README.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,9 @@ import { render, screen } from '@testing-library/react';
384384

385385
+ it('should call onSearch prop when it types on input change event', async () => {
386386
+ // Arrange
387-
+ const props = {
387+
+ const props: React.ComponentProps<typeof SearchBarComponent> = {
388388
+ search: '',
389-
+ onSearch: jest.fn(),
389+
+ onSearch: vi.fn(),
390390
+ labels: {
391391
+ placeholder: 'test placeholder',
392392
+ },
@@ -414,7 +414,7 @@ _./src/common/components/search-bar/search-bar.hook.spec.tsx_
414414
import { renderHook } from "@testing-library/react";
415415
import { useSearchBar } from "./search-bar.hook";
416416

417-
describe("common/components/search-bar/search-bar.hook specs", () => {
417+
describe("useSearchBar specs", () => {
418418
it('should return search text, onSearch method and filteredList when it feeds colors array and "name" field', () => {
419419
// Arrange
420420
// Act
@@ -431,7 +431,7 @@ _./src/common/components/search-bar/search-bar.hook.spec.tsx_
431431
import { renderHook } from '@testing-library/react';
432432
import { useSearchBar } from './search-bar.hook';
433433

434-
describe('common/components/search-bar/search-bar.hook specs', () => {
434+
describe('useSearchBar specs', () => {
435435
it('should return search text, onSearch method and filteredList when it feeds colors array and "name" field', () => {
436436
// Arrange
437437
+ const colors = [
@@ -499,15 +499,9 @@ Testing it calls to `useDebounce` hook:
499499

500500
_./src/common/components/search-bar/search-bar.hook.spec.tsx_
501501

502-
> Care with: import \* as commonHooks from 'common/hooks';
503-
>
504-
> https://stackoverflow.com/questions/53162001/typeerror-during-jests-spyon-cannot-set-property-getrequest-of-object-which
505-
>
506-
> https://github.com/babel/babel/issues/8363
507-
508502
```diff
509503
import { renderHook, act } from '@testing-library/react';
510-
+ import * as commonHooks from 'common/hooks/debounce.hook';
504+
+ import * as commonHooks from '#common/hooks';
511505
import { useSearchBar } from './search-bar.hook';
512506
...
513507

@@ -518,7 +512,7 @@ import { useSearchBar } from './search-bar.hook';
518512
+ { id: 2, name: 'blue' },
519513
+ { id: 3, name: 'green' },
520514
+ ];
521-
+ const debounceSearchStub = jest.spyOn(commonHooks, 'useDebounce');
515+
+ const debounceSearchStub = vi.spyOn(commonHooks, 'useDebounce');
522516

523517
+ // Act
524518
+ renderHook(() => useSearchBar(colors, ['name']));
@@ -543,7 +537,7 @@ _./src/common/components/search-bar/search-bar.hook.spec.tsx_
543537
+ { id: 2, name: 'blue' },
544538
+ { id: 3, name: 'green' },
545539
+ ];
546-
+ const debounceSearchStub = jest
540+
+ const debounceSearchStub = vi
547541
+ .spyOn(commonHooks, 'useDebounce')
548542
+ .mockReturnValue('blue');
549543

@@ -564,8 +558,8 @@ _./src/common/components/search-bar/search-bar.hook.spec.tsx_
564558

565559
```diff
566560
import { renderHook, act, waitFor } from '@testing-library/react';
567-
import * as commonHooks from 'common/hooks/debounce.hook';
568-
+ import * as filterHelpers from 'common/helpers/filter.helpers';
561+
import * as commonHooks from '#common/hooks';
562+
+ import * as filterHelpers from '#common/helpers';
569563
import { useSearchBar } from './search-bar.hook';
570564
...
571565

@@ -576,7 +570,7 @@ import { useSearchBar } from './search-bar.hook';
576570
+ { id: 2, name: 'blue' },
577571
+ { id: 3, name: 'green' },
578572
+ ];
579-
+ const filterByTextStub = jest.spyOn(filterHelpers, 'filterByText');
573+
+ const filterByTextStub = vi.spyOn(filterHelpers, 'filterByText');
580574

581575
+ // Act
582576
+ renderHook(() => useSearchBar(colors, ['name']));
@@ -601,7 +595,7 @@ _./src/common/components/search-bar/search-bar.hook.spec.tsx_
601595
+ { id: 2, name: 'blue' },
602596
+ { id: 3, name: 'green' },
603597
+ ];
604-
+ const filterByTextStub = jest
598+
+ const filterByTextStub = vi
605599
+ .spyOn(filterHelpers, 'filterByText')
606600
+ .mockReturnValue([
607601
+ { id: 2, name: 'blue' },

0 commit comments

Comments
 (0)