Skip to content

Commit

Permalink
test(react): useDebouncedInputValue 테스트 코드 개선 (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssi02014 authored Dec 9, 2024
1 parent 52131b7 commit 5abdf0e
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { screen } from '@testing-library/react';
import { screen, waitFor } from '@testing-library/react';
import { useDebouncedInputValue } from '.';
import { renderSetup } from '../../_internal/test/renderSetup';
import { delay } from '@modern-kit/utils';
Expand Down Expand Up @@ -34,13 +34,17 @@ describe('useDebouncedInputValue', () => {

await delay(DELAY / 2);

expect(defaultValue).toHaveTextContent('test');
expect(debouncedValue).toHaveTextContent('');
await waitFor(() => {
expect(defaultValue).toHaveTextContent('test');
expect(debouncedValue).toHaveTextContent('');
});

await delay(DELAY / 2);

expect(defaultValue).toHaveTextContent('test');
expect(debouncedValue).toHaveTextContent('test');
await waitFor(() => {
expect(defaultValue).toHaveTextContent('test');
expect(debouncedValue).toHaveTextContent('test');
});
});

it('reset 함수가 호출되면 기본 값과 디바운스된 값이 모두 초기화되야합니다.', async () => {
Expand All @@ -57,13 +61,17 @@ describe('useDebouncedInputValue', () => {
await user.type(input, 'test');
await delay(DELAY);

expect(defaultValue).toHaveTextContent('test');
expect(debouncedValue).toHaveTextContent('test');
await waitFor(() => {
expect(defaultValue).toHaveTextContent('test');
expect(debouncedValue).toHaveTextContent('test');
});

await user.click(resetButton);
await delay(DELAY);

expect(defaultValue).toHaveTextContent('');
expect(debouncedValue).toHaveTextContent('');
await waitFor(() => {
expect(defaultValue).toHaveTextContent('');
expect(debouncedValue).toHaveTextContent('');
});
});
});

0 comments on commit 5abdf0e

Please sign in to comment.