Skip to content

Commit 36334a6

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Add Fantom itest for LogBoxButton
Differential Revision: D94890196
1 parent 63de60b commit 36334a6

2 files changed

Lines changed: 73 additions & 54 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
12+
13+
import * as Fantom from '@react-native/fantom';
14+
import LogBoxButton from 'react-native/Libraries/LogBox/UI/LogBoxButton';
15+
import * as React from 'react';
16+
import {Text} from 'react-native';
17+
18+
describe('LogBoxButton', () => {
19+
it('should render only a view without an onPress', () => {
20+
const root = Fantom.createRoot();
21+
22+
Fantom.runTask(() => {
23+
root.render(
24+
<LogBoxButton
25+
backgroundColor={{
26+
default: 'black',
27+
pressed: 'red',
28+
}}>
29+
<Text>Press me</Text>
30+
</LogBoxButton>,
31+
);
32+
});
33+
34+
// When there is no onPress, the component renders a View wrapping children.
35+
// StyleSheet.compose with no additional style results in an array output
36+
// from the renderer (two sibling nodes), compared via toJSON array form.
37+
const output = root.getRenderedOutput({props: []}).toJSON();
38+
expect(Array.isArray(output)).toBe(true);
39+
if (Array.isArray(output)) {
40+
expect(output).toHaveLength(2);
41+
expect(output[0]).toEqual({type: 'View', props: {}, children: []});
42+
expect(output[1]).toEqual({
43+
type: 'Paragraph',
44+
props: {},
45+
children: ['Press me'],
46+
});
47+
}
48+
});
49+
50+
it('should render a view with onPress provided', () => {
51+
const root = Fantom.createRoot();
52+
53+
Fantom.runTask(() => {
54+
root.render(
55+
<LogBoxButton
56+
backgroundColor={{
57+
default: 'black',
58+
pressed: 'red',
59+
}}
60+
hitSlop={{}}
61+
onPress={() => {}}>
62+
<Text>Press me</Text>
63+
</LogBoxButton>,
64+
);
65+
});
66+
67+
expect(root.getRenderedOutput({props: []}).toJSX()).toEqual(
68+
<rn-view>
69+
<rn-paragraph>Press me</rn-paragraph>
70+
</rn-view>,
71+
);
72+
});
73+
});

packages/react-native/Libraries/LogBox/UI/__tests__/LogBoxButton-test.js

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

0 commit comments

Comments
 (0)