Skip to content

Commit c937439

Browse files
huntiefacebook-github-bot
authored andcommitted
Add a basic Jest test to helloworld (facebook#51534)
Summary: Pull Request resolved: facebook#51534 Aims to give us CI coverage of React Native's Jest preset, preventing future bugs like facebook#51525. Changes: - Add a basic "it renders" Jest test to helloworld - Add "Run Helloworld tests" step to `test-ios-helloworld` job in CI - Also convert helloworld's `App.tsx` to TypeScript, as easiest way to unblock Jest JSX behaviour. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D75218901 fbshipit-source-id: 601155c59c4483696971df4c29d51549d97f49f2
1 parent 0acd082 commit c937439

File tree

6 files changed

+39
-3
lines changed

6 files changed

+39
-3
lines changed

.github/actions/test-ios-helloworld/action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ runs:
8383
8484
yarn bootstrap ios "${args[@]}" | cat
8585
86-
- name: Build HelloWorld project
86+
- name: Run Helloworld tests
87+
shell: bash
88+
run: |
89+
cd packages/helloworld
90+
yarn test
91+
92+
- name: Build HelloWorld project
8793
shell: bash
8894
run: |
8995
cd packages/helloworld

packages/helloworld/App.jsx renamed to packages/helloworld/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow strict-local
87
* @format
98
*/
109

@@ -19,7 +18,7 @@ import {
1918
useColorScheme,
2019
} from 'react-native';
2120

22-
function App(): React.Node {
21+
function App(): React.ReactNode {
2322
const isDarkMode = useColorScheme() === 'dark';
2423

2524
return (
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
* @format
8+
*/
9+
10+
import App from '../App';
11+
import React from 'react';
12+
import ReactTestRenderer from 'react-test-renderer';
13+
14+
test('renders correctly', async () => {
15+
await ReactTestRenderer.act(() => {
16+
ReactTestRenderer.create(<App />);
17+
});
18+
});

packages/helloworld/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"@react-native/core-cli-utils": "0.80.0-main",
2424
"@react-native/eslint-config": "0.80.0-main",
2525
"@react-native/metro-config": "0.80.0-main",
26+
"@react-native/typescript-config": "0.80.0-main",
27+
"@types/jest": "^29.5.14",
2628
"chalk": "^4.1.2",
2729
"commander": "^12.0.0",
2830
"eslint": "^8.19.0",

packages/helloworld/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@react-native/typescript-config"
3+
}

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,14 @@
19181918
dependencies:
19191919
"@types/istanbul-lib-report" "*"
19201920

1921+
"@types/jest@^29.5.14":
1922+
version "29.5.14"
1923+
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.14.tgz#2b910912fa1d6856cadcd0c1f95af7df1d6049e5"
1924+
integrity sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ==
1925+
dependencies:
1926+
expect "^29.0.0"
1927+
pretty-format "^29.0.0"
1928+
19211929
"@types/jest@^29.5.3":
19221930
version "29.5.12"
19231931
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.12.tgz#7f7dc6eb4cf246d2474ed78744b05d06ce025544"

0 commit comments

Comments
 (0)