Skip to content

Commit

Permalink
Tests: fix async updates in tests (#540)
Browse files Browse the repository at this point in the history
* test(LineFilter): fix test

* test(PatternControls): fix test
  • Loading branch information
matyax authored Jul 9, 2024
1 parent cfe10de commit 3005a1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Components/IndexScene/PatternControls.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { PatternControls } from './PatternControls';
import { render, screen } from '@testing-library/react';
import { act, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { AppliedPattern } from './IndexScene';

Expand Down Expand Up @@ -36,7 +36,7 @@ describe('PatternControls', () => {
const onRemove = jest.fn();
render(<PatternControls patterns={[{ pattern: patterns[0], type: 'include' }]} onRemove={onRemove} />);

await userEvent.click(screen.getByLabelText('Remove pattern'));
await act(() => userEvent.click(screen.getByLabelText('Remove pattern')));
expect(onRemove).toHaveBeenCalledTimes(1);
});

Expand Down
6 changes: 3 additions & 3 deletions src/Components/ServiceScene/LineFilter.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { act, render, screen } from '@testing-library/react';
import { LineFilter } from './LineFilter';
import userEvent from '@testing-library/user-event';
import { CustomVariable, SceneVariableSet } from '@grafana/scenes';
Expand All @@ -26,7 +26,7 @@ describe('LineFilter', () => {
test('Updates the variable with the user input', async () => {
render(<scene.Component model={scene} />);

await userEvent.type(screen.getByPlaceholderText('Search in log lines'), 'some text');
await act(() => userEvent.type(screen.getByPlaceholderText('Search in log lines'), 'some text'));

expect(await screen.findByDisplayValue('some text')).toBeInTheDocument();
expect(lineFilterVariable.getValue()).toBe('|~ `(?i)some text`');
Expand All @@ -35,7 +35,7 @@ describe('LineFilter', () => {
test('Escapes the regular expression in the variable', async () => {
render(<scene.Component model={scene} />);

await userEvent.type(screen.getByPlaceholderText('Search in log lines'), '(characters');
await act(() => userEvent.type(screen.getByPlaceholderText('Search in log lines'), '(characters'));

expect(await screen.findByDisplayValue('(characters')).toBeInTheDocument();
expect(lineFilterVariable.getValue()).toBe('|~ `(?i)\\(characters`');
Expand Down

0 comments on commit 3005a1c

Please sign in to comment.