Testing · React Native - Deepstash

Bite‑sized knowledge

to upgrade

your career

Ideas from books, articles & podcasts.

published 12 ideas

Testing · React Native

reactnative.dev

Testing in React Native

As your codebase expands, small errors and edge cases you don’t expect can cascade into larger failures. Bugs lead to bad user experience and ultimately, business losses. One way to prevent fragile programming is to test your code before releasing it into the wild.

There is more value in te...

5

STASHED IN:

7

The default template of React Native ships with Jest testing framework. It includes a preset that's tailored to this environment so you can get productive without tweaking the configuration and mocks straight away—

STASHED IN:

7

Structuring Tests

Your tests should be short and ideally test only one thing.

The test in the image is described by the string passed to the it function. Take good care writing the description so that it’s clear what is being tested...

1

STASHED IN:

8

Jest offers describe function to help structure your tests. Use describe to group together all tests that belong to one functionality. Describes can be nested, if you need that. Other functions yo...

STASHED IN:

7

Unit tests

Unit tests cover the smallest parts of code, like individual functions or classes.

The great thing about unit tests is that they are quick to write and run. Therefore, as you work, you get fast feedback about whether your tests are passing.

STASHED IN:

7

Sometimes, when your tested objects have external dependencies, you’ll want to “mock them out.” “Mocking” is when you replace some dependency of your code with your own implementation.

Jest comes with

STASHED IN:

7

In integration testing, real individual units are combined (same as in your app) and tested together to ensure that their cooperation works as expected. This is not to say that mocking does not happen here: you’ll still need mocks (for example, to mock communication with a weathe...

STASHED IN:

7

For testing React components, there are two things you may want to test:

  • Interaction: to ensure the component behaves correctly when interacted with by a user (eg. when user presses a button)
  • Rendering: to ensure the component render output used by React is co...

STASHED IN:

7

Component Tests

There are several libraries that can help you testing these:

  • React’s Test Renderer, developed alongside its core, provides a React renderer that can be used to render React components to pure JavaScript objects, w...

STASHED IN:

7

Avoid testing implementation details like props or state—while such tests work, they are not oriented toward how users will interact with the component and tend to break by refactoring (for example when you'd like to rename some things or rewrite class component using hooks).

R...

STASHED IN:

7

Snapshot testing is an advanced kind of testing enabled by Jest.

A "component snapshot" is a textual representation of your component’s render output generated during a test run.

With snapshot testing, you typically fir...

STASHED IN:

8

End-to-End Tests

In end-to-end (E2E) tests, you verify your app is working as expected on a device (or a simulator / emulator) from the user perspective.

This is done by building your app in the release configuration and running the tests against it.

E2E tests give you the highest pos...

STASHED IN:

7

0 Comments

Discover and save more ideas by creating a

FREE

Deepstash account.

Develop a

reading habit

, save

time

and create an amazing

knowledge library

.

GET THE APP: