diff --git a/.umirc.ts b/.umirc.ts index 4a422ff..28e570a 100644 --- a/.umirc.ts +++ b/.umirc.ts @@ -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', diff --git a/docs/examples/basic.tsx b/docs/examples/basic.tsx index 4d57814..d8c3b6e 100644 --- a/docs/examples/basic.tsx +++ b/docs/examples/basic.tsx @@ -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(true); - const onMutate = useCallback((mutations: MutationRecord[]) => { + const onMutate = (mutations: MutationRecord[]) => { console.log(mutations); - }, []); + }; return ( diff --git a/package.json b/package.json index e2d302c..37a6577 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", diff --git a/tests/index.test.tsx b/tests/index.test.tsx index c9afeb2..7fd68ed 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -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(true); @@ -20,11 +20,7 @@ describe('MutateObserver', () => { }; const { container, unmount } = render(); fireEvent.click(container.querySelector('button')!); - if ('MutationObserver' in window) { - expect(fn).toHaveBeenCalled(); - } else { - expect(fn).not.toHaveBeenCalled(); - } + await waitFor(() => expect(fn).toHaveBeenCalled()); unmount(); });