Skip to content

Commit

Permalink
chore: restructure sections
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-perkins committed Mar 31, 2023
1 parent 4f255fe commit d9b690d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
6 changes: 1 addition & 5 deletions docs/react/testing/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ There are two types of tests that can be written:

[**Playwright**](https://playwright.dev): Playwright is a browser automation library that's used to run end-to-end tests. It allows developers to test the entire application, including the user interface, in a simulated environment.

## Conclusion

Testing is an important part of the development process, and React provides a robust set of tools and libraries for testing applications. By writing and running tests, you can ensure that your application is working as intended and catch bugs before they reach production.

### Additional Resources
## Additional Resources

- [Testing Ionic React Apps with Jest and React Testing Library](https://ionicframework.com/blog/testing-ionic-react-apps-with-jest-and-react-testing-library/)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ title: Ionic React Unit Testing Setup
description: Learn how to set up unit tests for an Ionic React application.
---

# Setup
# Unit Testing Setup

Ionic requires a few additional steps to set up unit tests.

## Install Jest

### React Scripts
## Jest

If your React project is using `react-scripts`, jest is already installed. You can confirm the version of Jest by running:

Expand All @@ -24,15 +22,15 @@ Ionic recommends `react-scripts@5` and requires a minimum version of `jest@27`,
npm install react-scripts@latest
```

## Install React Testing Library
### Install React Testing Library

React Testing Library is a set of utilities that make it easier to test React components. It's used to interact with components and test their behavior.

```bash
npm install --save-dev @testing-library/react @testing-library/jest-dom @testing-library/user-event
```

## Initialize Ionic React
### Initialize Ionic React

Ionic React requires the `setupIonicReact` function to be called before any tests are run. Failing to do so will result in mode-based classes and platform behaviors not being applied to your components.

Expand All @@ -44,12 +42,10 @@ import { setupIonicReact } from '@ionic/react';
setupIonicReact();
```

## Test Environment
### Test Environment

Ionic requires a DOM environment to be available in order to render components. This is typically provided by the `jsdom` test environment. In Jest 27 and later, the default environment is `node`.

### React Scripts

To configure this behavior, update your `test` command to include `--env=jsdom`:

```json title="package.json"
Expand Down
36 changes: 13 additions & 23 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ module.exports = {
type: 'category',
label: 'Upgrade Guides',
collapsed: false,
items: [
'updating/7-0',
'updating/6-0',
'updating/5-0',
'updating/4-0'
]
items: ['updating/7-0', 'updating/6-0', 'updating/5-0', 'updating/4-0'],
},
{
type: 'category',
Expand All @@ -30,7 +25,7 @@ module.exports = {
'developing/tips',
'developing/hardware-back-button',
'developing/keyboard',
'developing/config'
'developing/config',
],
},
{
Expand All @@ -45,7 +40,7 @@ module.exports = {
href: '/docs/api/grid',
},
'layout/global-stylesheets',
'layout/css-utilities'
'layout/css-utilities',
],
},
{
Expand Down Expand Up @@ -129,9 +124,13 @@ module.exports = {
type: 'category',
label: 'Testing',
items: [
'react/testing/introduction',
'react/testing/setup',
'react/testing/examples'
'react/testing/introduction',
{
type: 'category',
label: 'Unit Testing',
collapsed: false,
items: ['react/testing/unit-testing/setup', 'react/testing/unit-testing/examples'],
},
],
},
'react/performance',
Expand Down Expand Up @@ -237,7 +236,7 @@ module.exports = {
href: 'https://github.com/ionic-team/ionic/blob/master/CHANGELOG.md',
},
'reference/support',
'reference/browser-support'
'reference/browser-support',
],
},
],
Expand Down Expand Up @@ -370,12 +369,7 @@ module.exports = {
type: 'category',
label: 'Media',
collapsed: false,
items: [
'api/avatar',
'api/icon',
'api/img',
'api/thumbnail',
],
items: ['api/avatar', 'api/icon', 'api/img', 'api/thumbnail'],
},
{
type: 'category',
Expand Down Expand Up @@ -528,11 +522,7 @@ module.exports = {
type: 'category',
label: 'Getting Started',
collapsed: false,
items: [
'native',
'native-setup',
'native-faq',
],
items: ['native', 'native-setup', 'native-faq'],
},
{
type: 'category',
Expand Down

0 comments on commit d9b690d

Please sign in to comment.