Skip to content

The new RNW app template should enable testing via rnx-kit #11939

Closed
@jonthysell

Description

@jonthysell

Summary

When adding RNW support to an RN app, the template should enable the capacity to run the jest mock renderer tests targeting the windows platform. This can be done by:

  1. Adding @rnx-kit/cli and @rnx-kit/jest-preset to the app's dev dependencies
  2. Modifying the app's jest configuration to use @rnx-kit/jest-preset
  3. Make it easy to test windows by calling react-native rnx-test --platform windows

Furthermore, once this is enabled, we should add a task calling the tests to the cli-init.yml pipeline to verify we don't break testing in the future.

Motivation

When creating a new RN app with npx react-native init the template includes the setup for jest tests using the react-native jest preset and a simple renderer test that validates the JSX of the app.

However, if you add RNW and start using RNW components, you risk running into failures because the by default the setup only ever tests the app as-if running on the ios platform (see #11938 for an example).

While you could theoretically use the given options to the react-native jest preset to ensure the correct modules are loaded / mocked appropriately, the much better alternative would be to use the @rnx-kit/jest-preset which does the work for us, as well as the @rnx-kit/cli's rnx-test command which can take a --platform parameter.

Basic Example

Example of modifying an app to use @rnx-kit here: jonthysell/rnw-issue-11938@f21b7fb

Open Questions

How risky is this? Should this be optional and/or just documented? Perhaps as a test:windows command?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions