Skip to content

Commit 270a37a

Browse files
authored
Merge pull request #9 from jason89521/fix-ant-test
2 parents 73ac32a + d76cea9 commit 270a37a

15 files changed

Lines changed: 331 additions & 416 deletions

__test__/Typist.test.tsx

Lines changed: 0 additions & 81 deletions
This file was deleted.

__test__/utils.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"scripts": {
3434
"commit": "cz",
3535
"dev": "vite",
36-
"test": "jest ./__test__/Typist.test.tsx",
36+
"test": "jest",
3737
"build:example": "tsc && vite build",
3838
"build:types": "rimraf types/* && tsc --project tsconfig.lib.json",
3939
"build:lib": "yarn build:types && vite build --mode lib && api-extractor run",

src/TypistCore.ts

Lines changed: 0 additions & 187 deletions
This file was deleted.

src/__test__/Typist.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import { getByText, render } from '@testing-library/react';
3+
4+
import Typist from '..';
5+
import { nestedChildren, textsArray } from './constant';
6+
import { waitFor } from './utils';
7+
8+
beforeEach(() => {
9+
jest.useFakeTimers();
10+
});
11+
12+
test('render children correctly', async () => {
13+
const { container } = render(<Typist>{nestedChildren}</Typist>);
14+
15+
for (const texts of textsArray) {
16+
for (const text of texts) {
17+
await waitFor(() => {
18+
getByText(container, text);
19+
});
20+
}
21+
jest.runOnlyPendingTimers();
22+
}
23+
});

src/__test__/constant.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import Typist from '..';
3+
4+
export const textsArray = [
5+
['a'],
6+
['ab'],
7+
['ab', 'c'],
8+
['ab', 'cd'],
9+
['ab', 'c'],
10+
['ab'],
11+
['ab', 'e'],
12+
['ab', 'ef'],
13+
['ab', 'ef', 'gh'],
14+
];
15+
16+
export const nestedChildren = (
17+
<div className="ab">
18+
ab
19+
<div className="cd">cd</div>
20+
<Typist.Backspace count={2} />
21+
<div className="ef">ef</div>
22+
<Typist.Paste>
23+
<span>gh</span>
24+
</Typist.Paste>
25+
</div>
26+
);
27+
28+
export const WRAPPER_ID = 'wrapper';
29+
export const BUTTON_ID = 'button';

src/__test__/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { waitForOptions } from '@testing-library/react';
2+
import { waitFor as originWaitFor } from '@testing-library/react';
3+
4+
export function waitFor<T>(callback: () => Promise<T> | T, options?: waitForOptions) {
5+
return originWaitFor(callback, { interval: 0, ...options });
6+
}

src/components/Delay.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ type Props = {
33
ms: number;
44
};
55

6-
const Pause = (props: Props) => {
6+
const Delay = (props: Props) => {
77
return null;
88
};
99

10-
export default Pause;
10+
export default Delay;

0 commit comments

Comments
 (0)