Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update test #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { defineConfig } from 'dumi';

export default defineConfig({
title: 'rc-util',
title: 'rc-mutate-observer',
favicon: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4',
logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4',
outputPath: '.doc',
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import MutateObserver from '../../src';
import React, { useCallback } from 'react';
import React from 'react';

const App: React.FC = () => {
const [flag, setFlag] = React.useState<boolean>(true);

const onMutate = useCallback((mutations: MutationRecord[]) => {
const onMutate = (mutations: MutationRecord[]) => {
console.log(mutations);
}, []);
};

return (
<MutateObserver onMutate={onMutate}>
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish",
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
"start": "dumi dev",
"test": "umi-test",
"test:coverage": "npm run test --coverage",
"test": "rc-test",
"test:coverage": "rc-test --coverage",
"watch": "father dev"
},
"dependencies": {
Expand All @@ -59,10 +59,10 @@
"gh-pages": "^3.1.0",
"np": "^5.0.3",
"prettier": "^2.1.2",
"rc-test": "^7.0.15",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"typescript": "^4.6.3",
"umi-test": "^1.9.7"
"typescript": "^4.6.3"
},
"peerDependencies": {
"react": ">=16.9.0",
Expand Down
10 changes: 3 additions & 7 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { fireEvent, render, waitFor } from '@testing-library/react';
import MutateObserver from '../src';

describe('MutateObserver', () => {
it('MutateObserver should support onMutate', () => {
it('MutateObserver should support onMutate', async () => {
const fn = jest.fn();
const Demo: React.FC = () => {
const [flag, setFlag] = React.useState<boolean>(true);
Expand All @@ -20,11 +20,7 @@ describe('MutateObserver', () => {
};
const { container, unmount } = render(<Demo />);
fireEvent.click(container.querySelector('button')!);
if ('MutationObserver' in window) {
expect(fn).toHaveBeenCalled();
} else {
expect(fn).not.toHaveBeenCalled();
}
await waitFor(() => expect(fn).toHaveBeenCalled());
unmount();
});

Expand Down