Skip to content

Commit f9f3696

Browse files
author
hy
committed
fix:添加NoticeBar 通告栏组件测试用例
1 parent 647adeb commit f9f3696

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

packages/core/src/NoticeBar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const NoticeBar = (props: NoticeBarProps) => {
4040
operationDom = <View style={styles.actionWrap}>{action ? action : <Text style={[styles.link]}></Text>}</View>;
4141
}
4242
const main = (
43-
<View style={[styles.notice, style]}>
43+
<View style={[styles.notice, style]} testID="RNE__NoticeBar__style">
4444
{icon && <View style={styles.left15}>{icon}</View>}
4545
<View style={[styles.container, icon ? styles.left6 : styles.left15]}>
4646
<Marquee style={[styles.content, textStyle]} text={children} {...marqueeProps} />
@@ -54,7 +54,7 @@ const NoticeBar = (props: NoticeBarProps) => {
5454
mode === 'closable' ? (
5555
main
5656
) : (
57-
<TouchableWithoutFeedback onPress={onPress}>{main}</TouchableWithoutFeedback>
57+
<TouchableWithoutFeedback onPress={onPress} testID="RNE__NoticeBar__link" >{main}</TouchableWithoutFeedback>
5858
)
5959
) : null}
6060
</View>

test-ci/src/__tests__/noticeBar.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,30 @@ describe('NoticeBar', () => {
4444
expect(component.props.style).toMatchObject({ fontSize: 12 });
4545
});
4646

47-
// it('onPress', () => {
48-
// const fn = jest.fn();
49-
// const { getByTestId } = render(<NoticeBar onPress={fn}>onPress</NoticeBar>);
50-
// const component = getByTestId('RNE__NoticeBar__wrap');
51-
// fireEvent(component, 'press');
52-
// expect(fn).toHaveBeenCalled();
53-
// });
47+
it('textStyle', () => {
48+
const { UNSAFE_getByType } = render(<NoticeBar textStyle={{ fontSize: 20 }} />);
49+
const component = UNSAFE_getByType(Marquee);
50+
expect(component.props.style[1].fontSize).toBe(20);
51+
});
52+
53+
it('onPress events', () => {
54+
const fn = jest.fn();
55+
const { getByTestId } = render(<NoticeBar mode="link" onPress={fn}>onPress</NoticeBar>);
56+
const component = getByTestId('RNE__NoticeBar__link');
57+
fireEvent(component, 'press');
58+
expect(fn).toHaveBeenCalled();
59+
});
5460

55-
// it('action', () => {
56-
// const { getByText } = render(<NoticeBar action={<Text>去看看</Text>} />);
57-
// expect(getByText('去看看')).toBeTruthy();
58-
// });
61+
it('action', () => {
62+
const { getByText } = render(<NoticeBar mode="closable" action={<Text>去看看</Text>} />);
63+
expect(getByText('去看看')).toBeTruthy();
64+
});
5965

60-
// it('style', () => {
61-
// const { getByTestId } = render(<NoticeBar style={{ height: 50 }} />);
62-
// const component = getByTestId('RNE__NoticeBar__wrap');
63-
// const styles = toObject(component.props.style);
64-
// expect(styles.height).toBe(50);
65-
// });
66+
it('style', () => {
67+
const { getByTestId } = render(<NoticeBar mode="closable" style={{ height: 50 }} />);
68+
const component = getByTestId('RNE__NoticeBar__style');
69+
const styles = toObject(component.props.style);
70+
expect(styles.height).toBe(50);
71+
});
6672

67-
// it('textStyle', () => {
68-
// const { getByTestId } = render(<NoticeBar textStyle={{ fontSize: 20 }} />);
69-
// const component = getByTestId('RNE__NoticeBar__div');
70-
// const styles = toObject(component.props.style);
71-
// expect(styles.fontSize).toBe(20);
72-
// });
7373
});

0 commit comments

Comments
 (0)