Skip to content

Commit ec58148

Browse files
committedJul 11, 2023
fix:修复测试用例动画问题
1 parent 43ec91f commit ec58148

File tree

7 files changed

+75
-21
lines changed

7 files changed

+75
-21
lines changed
 

‎example/examples/.watchman-cookie-yuzhouwuditianxinjiang-2.local-1329-629

Whitespace-only changes.

‎packages/core/src/NoticeBar/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Icon from '../Icon';
44
import Marquee, { MarqueeProps } from './Marquee';
55
import { Theme } from '../theme';
66
import { useTheme } from '@shopify/restyle';
7+
export { Marquee };
78

89
export type NoticeBarProps = {
910
children?: any;

‎test-ci/metro.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
12
const conf = require('@uimjs/metro-config');
2-
module.exports = conf.default();
3+
module.exports = mergeConfig(getDefaultConfig(__dirname), conf.default());

‎test-ci/package.json

+23-11
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,41 @@
1111
},
1212
"dependencies": {
1313
"react": "18.0.0",
14-
"react-native": "0.70.6"
14+
"react-native": "0.72.1"
1515
},
1616
"devDependencies": {
17+
"@react-native/metro-config": "~0.72.9",
18+
"@react-native-camera-roll/camera-roll": "5.3.1",
19+
"@react-native-community/masked-view": "~0.1.11",
20+
"@react-navigation/native": "~6.0.11",
21+
"@react-navigation/stack": "~6.2.2",
22+
"@uiw/react-native": "4.0.11",
23+
"@uiw/react-native-image-picker": "4.0.11",
24+
"react": "18.0.0",
25+
"react-native": "0.69.7",
26+
"react-native-gesture-handler": "~2.5.0",
27+
"react-native-image-picker": "^5.3.1",
28+
"react-native-image-viewing": "~0.2.2",
29+
"react-native-safe-area-context": "~4.3.1",
30+
"react-native-screens": "~3.15.0",
31+
"react-native-svg": "13.9.0",
1732
"@babel/core": "^7.20.7",
1833
"@babel/runtime": "^7.20.7",
1934
"@react-native-community/eslint-config": "^2.0.0",
20-
"@testing-library/react-native": "^11.5.0",
35+
"@testing-library/react-native": "^12.1.2",
2136
"@tsconfig/react-native": "^2.0.2",
22-
"@types/jest": "^29.2.5",
37+
"@types/jest": "^29.5.3",
2338
"@types/react": "^18.0.21",
2439
"@types/react-native": "^0.70.6",
2540
"@types/react-test-renderer": "^18.0.0",
2641
"@typescript-eslint/eslint-plugin": "^5.37.0",
2742
"@typescript-eslint/parser": "^5.37.0",
28-
"@uiw/react-native": "4.0.10",
29-
"@uimjs/metro-config": "^1.0.2",
43+
"@uimjs/metro-config": "^2.0.1",
3044
"@shopify/restyle": "~2.4.2",
3145
"eslint": "^7.32.0",
32-
"jest": "^29.3.1",
46+
"jest": "^29.6.1",
3347
"metro-react-native-babel-preset": "0.72.3",
34-
"react-test-renderer": "18.1.0",
48+
"react-test-renderer": "18.2.0",
3549
"typescript": "^4.8.3",
3650
"@types/color": "~3.0.3",
3751
"@types/lodash": "~4.14.191",
@@ -41,12 +55,10 @@
4155
"color": "4.2.3",
4256
"lodash": "4.17.21",
4357
"prop-types": "15.7.2",
44-
"react-native-gesture-handler": "2.8.0",
45-
"react-native-root-siblings": "4.1.1",
46-
"react-native-svg": "13.9.0"
58+
"react-native-root-siblings": "4.1.1"
4759
},
4860
"jest": {
49-
"setupFiles": [
61+
"setupFilesAfterEnv": [
5062
"./mock.js"
5163
],
5264
"preset": "react-native",

‎test-ci/src/__tests__/radio.tsx

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,62 @@
11
import 'react-native';
22
import React from 'react';
33
import Radio from '../lib/Radio';
4-
import { render, fireEvent } from '@testing-library/react-native';
4+
import { render, fireEvent, act } from '@testing-library/react-native';
55

66
describe('Radio', () => {
77
it('disabled', () => {
8+
jest.useFakeTimers();
89
const { getByTestId } = render(<Radio disabled />);
10+
act(() => jest.runAllTimers());
11+
912
const component = getByTestId('RNE__Radio__view');
1013
expect(component.props.accessibilityState.disabled).toBe(true);
1114
});
1215

1316
it('borderColor', () => {
17+
jest.useFakeTimers();
1418
const { getByTestId } = render(<Radio borderColor="#bdc1cc" />);
19+
act(() => jest.runAllTimers());
20+
1521
const component = getByTestId('RNE__Radio__border');
22+
1623
expect(component.props.style.borderColor).toBe('#bdc1cc');
1724
});
1825

1926
it('checkedColor', () => {
27+
jest.useFakeTimers();
28+
2029
const { getByTestId } = render(<Radio checkedColor="#008EF0" />);
30+
act(() => jest.runAllTimers());
31+
2132
const component = getByTestId('RNE__Radio__box');
2233
expect(component.props.style.backgroundColor).toBe('#008EF0');
2334
});
2435

2536
it('circleSize', () => {
37+
jest.useFakeTimers();
2638
const { getByTestId } = render(<Radio circleSize={21} />);
39+
act(() => jest.runAllTimers());
2740
const component = getByTestId('RNE__Radio__border');
2841
expect(component.props.style.width).toBe(21);
2942
expect(component.props.style.height).toBe(21);
3043
});
3144

3245
it('onPress events', () => {
46+
jest.useFakeTimers();
3347
const fn = jest.fn();
3448
const { getByTestId } = render(<Radio onPress={fn} />);
49+
act(() => jest.runAllTimers());
3550
const component = getByTestId('RNE__Radio__view');
3651
fireEvent(component, 'press');
3752
expect(fn).toHaveBeenCalled();
3853
});
3954

4055
it('disabled onPress events', () => {
56+
jest.useFakeTimers();
4157
const fn = jest.fn();
4258
const { getByTestId } = render(<Radio disabled onPress={fn} />);
59+
act(() => jest.runAllTimers());
4360
const component = getByTestId('RNE__Radio__view');
4461
fireEvent(component, 'press');
4562
expect(fn).not.toHaveBeenCalled();

‎test-ci/src/__tests__/tooltip.tsx

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { View, Text } from 'react-native';
22
import React from 'react';
33
import Tooltip from '../lib/Tooltip';
4-
import { render, fireEvent } from '@testing-library/react-native';
4+
import { render, fireEvent, act } from '@testing-library/react-native';
55
import { toObject } from '../utils';
66

77
describe('Tooltip', () => {
88
it('title', () => {
9+
jest.useFakeTimers();
910
const { getByTestId, getByText } = render(
1011
<Tooltip title="标题">
1112
<View>
@@ -14,59 +15,81 @@ describe('Tooltip', () => {
1415
</Tooltip>,
1516
);
1617
const pressable = getByTestId('RNE__Tooltip__pressable');
18+
act(() => {
19+
jest.runAllTimers();
20+
});
1721
fireEvent(pressable, 'press');
1822
expect(getByText('标题')).toBeTruthy();
1923
});
2024
it('height', () => {
25+
jest.useFakeTimers();
2126
const { getByTestId } = render(
2227
<Tooltip title="标题" height={80}>
2328
<View>
2429
<Text>我是一个文本</Text>
2530
</View>
2631
</Tooltip>,
2732
);
33+
act(() => {
34+
jest.runAllTimers();
35+
});
2836
const pressable = getByTestId('RNE__Tooltip__pressable');
37+
// const component = getByTestId('RNE__Tooltip__wrap');
2938
fireEvent(pressable, 'press');
30-
const component = getByTestId('RNE__Tooltip__wrap');
31-
// expect(component.props.height).toBe(80);
39+
// expect(component.props.height).toBe(80)
3240
});
3341
it('width', () => {
42+
jest.useFakeTimers();
43+
3444
const { getByTestId } = render(
3545
<Tooltip title="标题" width={100}>
3646
<View>
3747
<Text>我是一个文本</Text>
3848
</View>
3949
</Tooltip>,
4050
);
51+
act(() => {
52+
jest.runAllTimers();
53+
});
4154
const pressable = getByTestId('RNE__Tooltip__pressable');
55+
// const component = getByTestId('RNE__Tooltip__wrap');
4256
fireEvent(pressable, 'press');
43-
const component = getByTestId('RNE__Tooltip__wrap');
44-
// expect(component.props.width).toBe(100);
57+
// expect(component.props.width).toBe(100)
4558
});
4659
it('backgroundColor', () => {
60+
jest.useFakeTimers();
4761
const { getByTestId } = render(
4862
<Tooltip backgroundColor="red" title="标题">
4963
<View>
5064
<Text>我是一个文本</Text>
5165
</View>
5266
</Tooltip>,
5367
);
68+
act(() => {
69+
jest.runAllTimers();
70+
});
5471
const pressable = getByTestId('RNE__Tooltip__pressable');
5572
fireEvent(pressable, 'press');
73+
5674
const component = getByTestId('RNE__Tooltip__cloud__view');
5775
const styles = toObject(component.props.style);
5876
expect(styles.backgroundColor).toBe('red');
5977
});
6078
it('borderRadius', () => {
79+
jest.useFakeTimers();
6180
const { getByTestId } = render(
6281
<Tooltip borderRadius={10} title="标题">
6382
<View>
6483
<Text>我是一个文本</Text>
6584
</View>
6685
</Tooltip>,
6786
);
87+
act(() => {
88+
jest.runAllTimers();
89+
});
6890
const pressable = getByTestId('RNE__Tooltip__pressable');
6991
fireEvent(pressable, 'press');
92+
7093
const component = getByTestId('RNE__Tooltip__cloud__view');
7194
const styles = toObject(component.props.style);
7295
expect(styles.borderRadius).toBe(10);

‎test-ci/tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// prettier-ignore
22
{
3-
"extends": "@tsconfig/react-native/tsconfig.json", /* Recommended React Native TSConfig base */
3+
"extends": "@tsconfig/react-native/tsconfig.json", /* Recommended React Native TSConfig base */
44
"compilerOptions": {
55
/* Visit https://aka.ms/tsconfig.json to read more about this file */
6-
6+
"jsx": "react-native" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
77
/* Completeness */
8-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
8+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
99
}
1010
}

0 commit comments

Comments
 (0)
Please sign in to comment.