Skip to content

Commit 1a4e0f9

Browse files
committed
test: wait for mutation observer callback
1 parent a1781e7 commit 1a4e0f9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

tests/index.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fireEvent, render } from '@testing-library/react';
1+
import { fireEvent, render, waitFor } from '@testing-library/react';
22
import React from 'react';
33
import MutateObserver from '../src';
44

@@ -15,7 +15,7 @@ describe('MutateObserver', () => {
1515
global.mutateTargetElement = null;
1616
});
1717

18-
it('MutateObserver should support onMutate', () => {
18+
it('MutateObserver should support onMutate', async () => {
1919
const fn = jest.fn();
2020
const Demo: React.FC = () => {
2121
const [flag, setFlag] = React.useState<boolean>(true);
@@ -37,7 +37,9 @@ describe('MutateObserver', () => {
3737

3838
// Check if the callback was triggered
3939
if ('MutationObserver' in window) {
40-
expect(fn).toHaveBeenCalled();
40+
await waitFor(() => {
41+
expect(fn).toHaveBeenCalled();
42+
});
4143
} else {
4244
expect(fn).not.toHaveBeenCalled();
4345
}

0 commit comments

Comments
 (0)