SlideShare a Scribd company logo
1 of 139
Download to read offline
Testing React Native Apps
As you get settled, write the answer to the following
question on Post-It notes. Write as many answers on
separates notes as you like. When you're done, put them
on the back wall.
What do you want to learn about testing in this workshop?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing React Native Apps
https://rnte.st/cr23
Clone the repo, build, and test!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
ReactNativeTesting.io
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Josh Justice
CodingItWrong.com
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Thank you, assistants!
— David Leuiliette
— Jon Major Condon
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Answer the following two questions on Post-It notes.
Then discuss your answers with your group. Choose
someone who will summarize your group's answers to
the whole workshop afterward.
1. What benefits are you currently getting from
testing?
2. What are your testing pain points?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Why Test?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
My Story
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing Pain Points
— Difficult to test
— Flaky tests
— Fragile tests
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Example-Based Tests
— Component tests (React Native Testing Library)
— End-to-end tests (Detox)
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Learning More Afterward
— https://rnte.st/cr23
— Discord community
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Questions and thoughts
welcome!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Stretch break!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
02 Component Tests:
Rendering
Testing React Native Apps
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
What is a component test?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
React Native Testing Library
@testing-library/react-native
callstack.github.io/react-native-testing-library
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
What to test?
— Call methods/functions?
— Check state values?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
"We don’t encourage reading implementation details
like state variables themselves…Instead, test observable
behavior — i.e. what your component renders or does."
-- @dan_abramov, 2019-03-06 tweet
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
"A component contract is the agreement between a
component and the rest of the application."
-- Edd Yerburgh, Testing Vue.js Applications
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
"Other components can assume the component will
fulfill its contractual agreement and produce the agreed
output if it’s provided the correct input."
-- Edd Yerburgh, Testing Vue.js Applications
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Discuss:
What are some of the kinds
of inputs and outputs that
components have?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
— Props
— User interaction events
Outputs:
— Rendered UI
— Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
— Props
— User interaction events
Outputs:
— Rendered UI
— Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
To the code!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Getter Functions
— screen.getByText
— screen.getByLabelText
— screen.getByPlaceholderText
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Text
return <Text>Hello, world!</Text>;
screen.getByText('Hello, world!')
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
TextInput
return <TextInput placeholder="Enter your name" ... />;
screen.getByPlaceholderText('Enter your name')
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Image
return (
<Image source={...} accessibilityLabel="squirrel waving" />
);
screen.getByLabelText('squirrel waving')
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
SVG
import WavingHand from './assets/waving-hand.svg';
return <WavingHand accessibilityLabel="waving hand" />;
screen.getByLabelText('waving hand')
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Which Query Should I Use?
callstack.github.io/react-native-testing-library/docs/how-should-i-query
"your test should resemble how users interact with your
code (component, page, etc.) as much as possible"
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Which Query Should I Use?
callstack.github.io/react-native-testing-library/docs/how-should-i-query
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Note on getByRole()
screen.getByRole('button', {name: 'Save Changes'})
— May become the top recommendation soon
— Feature needed first: implicit roles (Pressables
queryable as button by default)
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Confirming Presence
expect(screen.getBy…()).toBeVisible();
expect(screen.getBy…()).toBeOnTheScreen();
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Confirming Absence
expect(screen.queryBy…()).not.toBeOnTheScreen();
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Getter Functions
— screen.getByText
— screen.getByLabelText
— screen.getByPlaceholderText
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Query Functions
— screen.queryByText
— screen.queryByLabelText
— screen.queryByPlaceholderText
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
— Props
— User interaction events
Outputs:
— Rendered UI
— Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
— Props
— User interaction events
Outputs:
✅
Rendered UI
- Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
— Props
— User interaction events
Outputs:
✅
Rendered UI
- Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
To the code!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
— Props
— User interaction events
Outputs:
✅
Rendered UI
- Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
✅
Props
- User interaction events
Outputs:
✅
Rendered UI
- Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Exercise 1
— rn-testing-exercises
— exercises/Exercise1.md
For help:
reactnativetesting.io/component/testing/
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
A few more notes about testing
rendering and props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing content,
not appearance.
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
What about snapshot tests?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
import renderer from 'react-test-renderer';
import Hello from './Hello';
it('renders correctly', () => {
const tree = renderer.create(<Hello name="Josh" />).toJSON();
expect(tree).toMatchSnapshot();
});
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
03 Component Tests:
Actions and Mocks
Testing React Native Apps
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
✅
Props
- User interaction events
Outputs:
✅
Rendered UI
- Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
✅
Props
- User interaction events
Outputs:
✅
Rendered UI
- Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
To the code!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
import {fireEvent, render, screen} from '@testing-library/react-native';
describe('NewMessageForm', () => {
describe('pressing send', () => {
it('clears the message field', () => {
render(<NewMessageForm />);
fireEvent.changeText(
screen.getByPlaceholderText('Message'),
'Hello world',
);
fireEvent.press(screen.getByText('Send'));
expect(screen.getByPlaceholderText('Message')).toHaveProp('value', '');
});
});
});
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
fireEvent
import {fireEvent} from '@testing-library/react-native';
fireEvent.press(element)
fireEvent.changeText(element, text)
fireEvent.scroll(element, eventData)
fireEvent(element, eventName, eventData)
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
import {render, fireEvent} from '@testing-library/react-native';
describe('NewMessageForm', () => {
describe('pressing send', () => {
it('clears the message field', () => {
render(<NewMessageForm />);
fireEvent.changeText(
screen.getByPlaceholderText('Message'),
'Hello world',
);
fireEvent.press(screen.getByText('Send'));
expect(screen.getByPlaceholderText('Message')).toHaveProp('value', '');
});
});
});
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
toHaveProp
Provided by Jest Native
expect(...).toHaveProp('propName', 'propValue');
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
✅
Props
- User interaction events
Outputs:
✅
Rendered UI
- Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
✅
Props
✅
User interaction events
Outputs:
✅
Rendered UI
- Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
✅
Props
✅
User interaction events
Outputs:
✅
Rendered UI
- Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Mock Functions
jestjs.io/docs/mock-functions
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Creating a New Mock Function
const myMock = jest.fn().mockName('myMock');
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Mock Matchers
expect(myMock).toHaveBeenCalled();
expect(myMock).toHaveBeenCalledWith(arg, secondArg, ...);
expect(myMock).toHaveBeenCalledWith(expect.any(String));
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
To the code!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
it('calls the send handler', () => {
const messageText = 'Hello world';
const sendHandler = jest.fn().mockName('sendHandler');
render(<NewMessageForm onSend={sendHandler} />);
fireEvent.changeText(
screen.getByPlaceholderText('Message'),
messageText,
);
fireEvent.press(screen.getByText('Send'));
expect(sendHandler).toHaveBeenCalledWith(messageText);
});
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Question:
Do you think mocks involve
testing implementation
details or not?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
My view:
Mocks are an important
part of testing the contract.
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
✅
Props
✅
User interaction events
Outputs:
✅
Rendered UI
- Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
✅
Props
✅
User interaction events
Outputs:
✅
Rendered UI
✅
Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Exercise 2
— rn-testing-exercises
— exercises/Exercise2.md
For help:
reactnativetesting.io/component/testing/#interaction
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing the Contract
Inputs:
— Props
— User interaction events
Outputs:
— Rendered UI
— Calls to function props
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
04 Component Tests:
Effects and Module Mocks
Testing React Native Apps
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
How can we test effects?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
How can we test effects?
Test the result/"effect".
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Data loading effects hit the API
Problem?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Options for Mocking Web Service Requests
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Options for Mocking Web Service Requests
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Jest Module Mocks
jestjs.io/docs/mock-functions#mocking-modules
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
To the code!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
import {render, screen} from '@testing-library/react-native';
import RestaurantContainer from './RestaurantContainer';
import api from './api';
jest.mock('./api');
describe('RestaurantContainer', () => {
it('loads restaurants upon first render', async () => {
api.get.mockResolvedValue({/* the response object */});
render(<RestaurantContainer />);
expect(await screen.findByText('Pasta Place')).toBeVisible();
expect(screen.getByText('Salad Place')).toBeVisible();
expect(api.get).toHaveBeenCalledWith('/restaurants');
});
});
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
mockedModule.myfunc.mockReturnValue(val);
mockedModule.myfunc.mockResolvedValue(val);
mockedModule.myfunc.mockRejectedValue(val);
jestjs.io/docs/mock-function-api
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Getter Functions
— screen.getByText
— screen.getByLabelText
— screen.getByPlaceholderText
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Query Functions
— screen.queryByText
— screen.queryByLabelText
— screen.queryByPlaceholderText
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Find Functions
— await screen.findByText
— await screen.findByLabelText
— await screen.findByPlaceholderText
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Exercise 3
— rn-testing-exercises
— exercises/Exercise3.md
For help:
reactnativetesting.io/component/testing
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
act() Error
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
To the code!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Component Testing
As a group, come up a way to explain what "testing the
contract" of a component means to other developers.
Use the poster in your area. You can write a bulleted list,
use diagrams, draw a picture to use a metaphor, etc.
Feel free to get creative!
After, your group will present your board to the
workshop.
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
05 End-to-End Testing:
Basics
Testing React Native Apps
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
E2E Tests
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Choosing an E2E Test
Library
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
— Runs on Hardware
— Runs on Sauce Labs and AWS
Device Farm
— Runs completely outside your
app
— Have to use multiple libraries
together
— Hard to find complete
documentation
— Tests tend to be flaky
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Detox
— Write tests in JavaScript or
TypeScript
— Has inside knowledge of your
app
— Expo not officially supported
— Can be complex to set up
— Does not run on physical iOS
devices yet
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Maestro
— Easy setup, a single library
— Runs completely outside your
app
— Maestro Studio to
interactively write commands
— New; rough edges
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
To the code!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
it('detects text', async () => {
await expect(element(by.label('Hello, Lecture 5!'))).toBeVisible();
});
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
element(…)
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
it('should have welcome screen', async () => {
await expect(
element(by.label('Welcome to React Native!'))
).toBeVisible();
});
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Matchers
by.id()
by.text()
by.label()
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
await expect(element(by.id('welcome')))
.toBeVisible();
await expect(element(by.id('welcome')))
.toHaveText('Welcome to React Native!');
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Expectations
toExist()
toBeVisible()
toHaveText()
toHaveValue()
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
To the code!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
await element(by.id('mybutton')).tap();
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
await element(by.id('mytextinput'))
.typeText('I typed this');
await element(by.id('mytextinput'))
.clearText();
await element(by.id('mytextinput'))
.typeText('Something else');
await element(by.id('mytextinput'))
.replaceText('Something else');
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Actions
tap()
typeText()
clearText()
replaceText()
scroll()
swipe()
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
What to E2E test?
Main paths, not all edge cases
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
06 End-to-End Testing:
External Services
Testing React Native Apps
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Connecting to the real backend:
Upsides?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Connecting to the real backend:
Downsides?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Options for Mocking Web Service Requests
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Local web server?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Options for Mocking Web Service Requests
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Fake Module
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
What's a fake?
A version of the service that acts similar to the real thing
but stores its data in-memory
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
To the code!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
API file setup
api.js
api.mock.js
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
api.js
import axios from 'axios';
const api = axios.create({
baseURL: 'https://api.reactnativetesting.io',
// other config
});
export default api;
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
api.mock.js
const api = {
get() {
return Promise.resolve({
data: [
{id: 1, name: 'Widget 1'},
{id: 2, name: 'Widget 2'},
]
});
},
// ...
};
export default api;
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Configure metro.config.js
— Prefer .mock.js extension when present
— Exact code may differ if you've modified
metro.config.js for other reasons
— E.g. using react-native-svg-transformer
— See reactnativetesting.io/e2e/external-services
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
package.json
"start": "react-native start",
+"start:mock": "MOCK_API=true npm run start",
"test": "jest"
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
For Windows support
"start": "react-native start",
+"start:mock": "cross-env MOCK_API=true npm run start",
"test": "jest"
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Exercise 4
— rn-testing-exercises
— exercises/Exercise4.md
For help:
— reactnativetesting.io/e2e/testing
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Recommendation:
— Automate testing against a fake
— Manually test integration with real service
— If you need to automate testing with real service, do
a small separate test suite
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
End-to-End Testing
As a group, pick one of your group members' apps and
come up with a list of the most valuable scenarios you
would end-to-end test. Write each on a Post-It note and
put it on your poster. If there are any you're uncertain
how you would write a test for, discuss them as a group.
Nominate someone to present your scenarios and
questions to the whole workshop.
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
07 Wrap-up
Testing React Native Apps
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
How much of each type of
test to do?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Tradeoffs
— End-to-End Tests: give confidence the whole app
works
— Unit and Component Tests: faster, easier, less flaky
testing of edge cases, influence design of code
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
My Recommendations
— End-to-end test main flows only
— Component test edge cases
— Extract plain functions and classes when it makes
sense, and unit test them
— Tweak as you go
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
To Discuss
Write the answer to the following question on Post-It
note. Use as many as you need:
Based on what you learned today, what specifically do
you want to do differently testing your React app
going forward?
Afterward we'll go around the room and each share our
answers!
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Remaining Questions?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Remaining Questions?
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Continuing the Learning
— https://rnte.st/cr23
— https://reactnativetesting.io
— Discord community
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Effective Detox Testing
Oct 25, 2023 -Virtual
— CI on GitHub Actions
— Detox local development
workflow
— When Detox vs RNTL vs
manual
— How much to test with Detox
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
Thanks!
https://rnte.st/cr23survey
Josh Justice
josh.justice@testdouble.com
https://rnte.st/cr23
Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23

More Related Content

Similar to Testing React Native Apps - Chain React 2023

Vue and Firebase Experiences
Vue and Firebase ExperiencesVue and Firebase Experiences
Vue and Firebase ExperiencesIsatu Conteh
 
Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...
Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...
Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...Evgeniy Kuzmin
 
Contract testing | Евгений Кузьмин | CODEiD
Contract testing | Евгений Кузьмин | CODEiDContract testing | Евгений Кузьмин | CODEiD
Contract testing | Евгений Кузьмин | CODEiDCODEiD PHP Community
 
An Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorAn Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorCubet Techno Labs
 
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”GlobalLogic Ukraine
 
A Closer Look At React Native
A Closer Look At React NativeA Closer Look At React Native
A Closer Look At React NativeIan Wang
 
DevOps: Find Solutions, Not More Defects
DevOps: Find Solutions, Not More DefectsDevOps: Find Solutions, Not More Defects
DevOps: Find Solutions, Not More DefectsTechWell
 
3h à l'assaut d'une application réactive - Devoxx 2015
3h à l'assaut d'une application réactive - Devoxx 20153h à l'assaut d'une application réactive - Devoxx 2015
3h à l'assaut d'une application réactive - Devoxx 2015Publicis Sapient Engineering
 
Effective testing of rich internet applications
Effective testing of rich internet applicationsEffective testing of rich internet applications
Effective testing of rich internet applicationsRashwin
 
Contract testing. Getting started with Pact IO.
Contract testing. Getting started with Pact IO.Contract testing. Getting started with Pact IO.
Contract testing. Getting started with Pact IO.HYS Enterprise
 
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...Shift Conference
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Zach Lendon
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementZach Lendon
 
Reactive Application Using METEOR
Reactive Application Using METEORReactive Application Using METEOR
Reactive Application Using METEORNodeXperts
 

Similar to Testing React Native Apps - Chain React 2023 (20)

Vue and Firebase Experiences
Vue and Firebase ExperiencesVue and Firebase Experiences
Vue and Firebase Experiences
 
Resume
ResumeResume
Resume
 
Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...
Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...
Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...
 
Contract testing | Евгений Кузьмин | CODEiD
Contract testing | Евгений Кузьмин | CODEiDContract testing | Евгений Кузьмин | CODEiD
Contract testing | Евгений Кузьмин | CODEiD
 
Rahul kaduskar
Rahul kaduskarRahul kaduskar
Rahul kaduskar
 
Everything about Blind xss
Everything about Blind xssEverything about Blind xss
Everything about Blind xss
 
An Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorAn Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using Protractor
 
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
 
A Closer Look At React Native
A Closer Look At React NativeA Closer Look At React Native
A Closer Look At React Native
 
NEXT.JS
NEXT.JSNEXT.JS
NEXT.JS
 
elasticsearch X react
elasticsearch X reactelasticsearch X react
elasticsearch X react
 
DevOps: Find Solutions, Not More Defects
DevOps: Find Solutions, Not More DefectsDevOps: Find Solutions, Not More Defects
DevOps: Find Solutions, Not More Defects
 
3h à l'assaut d'une application réactive - Devoxx 2015
3h à l'assaut d'une application réactive - Devoxx 20153h à l'assaut d'une application réactive - Devoxx 2015
3h à l'assaut d'une application réactive - Devoxx 2015
 
Effective testing of rich internet applications
Effective testing of rich internet applicationsEffective testing of rich internet applications
Effective testing of rich internet applications
 
Contract testing. Getting started with Pact IO.
Contract testing. Getting started with Pact IO.Contract testing. Getting started with Pact IO.
Contract testing. Getting started with Pact IO.
 
REACTIVE A New Hope!
REACTIVE A New Hope!REACTIVE A New Hope!
REACTIVE A New Hope!
 
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
 
Reactive Application Using METEOR
Reactive Application Using METEORReactive Application Using METEOR
Reactive Application Using METEOR
 

More from Josh Justice

Designing Effective Tests with React Testing Library - React Day Berlin 2022
Designing Effective Tests with React Testing Library - React Day Berlin 2022Designing Effective Tests with React Testing Library - React Day Berlin 2022
Designing Effective Tests with React Testing Library - React Day Berlin 2022Josh Justice
 
Building for Mobile and Web with Expo - React Day Berlin 2022
Building for Mobile and Web with Expo - React Day Berlin 2022Building for Mobile and Web with Expo - React Day Berlin 2022
Building for Mobile and Web with Expo - React Day Berlin 2022Josh Justice
 
Building for Mobile and Web with Expo - React Advanced London 2022
Building for Mobile and Web with Expo - React Advanced London 2022Building for Mobile and Web with Expo - React Advanced London 2022
Building for Mobile and Web with Expo - React Advanced London 2022Josh Justice
 
Getting Better All the Time: How to Escape Bad Code
Getting Better All the Time: How to Escape Bad CodeGetting Better All the Time: How to Escape Bad Code
Getting Better All the Time: How to Escape Bad CodeJosh Justice
 
Sustainable Learning - ReactATL Jan 2022
Sustainable Learning - ReactATL Jan 2022Sustainable Learning - ReactATL Jan 2022
Sustainable Learning - ReactATL Jan 2022Josh Justice
 
Building an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoBuilding an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoJosh Justice
 
User-Modifiable Software: Smalltalk and HyperCard
User-Modifiable Software: Smalltalk and HyperCardUser-Modifiable Software: Smalltalk and HyperCard
User-Modifiable Software: Smalltalk and HyperCardJosh Justice
 
Practical Accessibility (A11y)
Practical Accessibility (A11y)Practical Accessibility (A11y)
Practical Accessibility (A11y)Josh Justice
 
Old Solutions to New Testing Problems
Old Solutions to New Testing ProblemsOld Solutions to New Testing Problems
Old Solutions to New Testing ProblemsJosh Justice
 
Test-Driven Development in Vue with Cypress
Test-Driven Development in Vue with CypressTest-Driven Development in Vue with Cypress
Test-Driven Development in Vue with CypressJosh Justice
 
Test-Driven Development in React with Cypress
Test-Driven Development in React with CypressTest-Driven Development in React with Cypress
Test-Driven Development in React with CypressJosh Justice
 
Newbie's Guide to Contributing to Babel
Newbie's Guide to Contributing to BabelNewbie's Guide to Contributing to Babel
Newbie's Guide to Contributing to BabelJosh Justice
 
Outside-in Testing in Vue with Cypress
Outside-in Testing in Vue with CypressOutside-in Testing in Vue with Cypress
Outside-in Testing in Vue with CypressJosh Justice
 

More from Josh Justice (13)

Designing Effective Tests with React Testing Library - React Day Berlin 2022
Designing Effective Tests with React Testing Library - React Day Berlin 2022Designing Effective Tests with React Testing Library - React Day Berlin 2022
Designing Effective Tests with React Testing Library - React Day Berlin 2022
 
Building for Mobile and Web with Expo - React Day Berlin 2022
Building for Mobile and Web with Expo - React Day Berlin 2022Building for Mobile and Web with Expo - React Day Berlin 2022
Building for Mobile and Web with Expo - React Day Berlin 2022
 
Building for Mobile and Web with Expo - React Advanced London 2022
Building for Mobile and Web with Expo - React Advanced London 2022Building for Mobile and Web with Expo - React Advanced London 2022
Building for Mobile and Web with Expo - React Advanced London 2022
 
Getting Better All the Time: How to Escape Bad Code
Getting Better All the Time: How to Escape Bad CodeGetting Better All the Time: How to Escape Bad Code
Getting Better All the Time: How to Escape Bad Code
 
Sustainable Learning - ReactATL Jan 2022
Sustainable Learning - ReactATL Jan 2022Sustainable Learning - ReactATL Jan 2022
Sustainable Learning - ReactATL Jan 2022
 
Building an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoBuilding an App for Mobile and Web with Expo
Building an App for Mobile and Web with Expo
 
User-Modifiable Software: Smalltalk and HyperCard
User-Modifiable Software: Smalltalk and HyperCardUser-Modifiable Software: Smalltalk and HyperCard
User-Modifiable Software: Smalltalk and HyperCard
 
Practical Accessibility (A11y)
Practical Accessibility (A11y)Practical Accessibility (A11y)
Practical Accessibility (A11y)
 
Old Solutions to New Testing Problems
Old Solutions to New Testing ProblemsOld Solutions to New Testing Problems
Old Solutions to New Testing Problems
 
Test-Driven Development in Vue with Cypress
Test-Driven Development in Vue with CypressTest-Driven Development in Vue with Cypress
Test-Driven Development in Vue with Cypress
 
Test-Driven Development in React with Cypress
Test-Driven Development in React with CypressTest-Driven Development in React with Cypress
Test-Driven Development in React with Cypress
 
Newbie's Guide to Contributing to Babel
Newbie's Guide to Contributing to BabelNewbie's Guide to Contributing to Babel
Newbie's Guide to Contributing to Babel
 
Outside-in Testing in Vue with Cypress
Outside-in Testing in Vue with CypressOutside-in Testing in Vue with Cypress
Outside-in Testing in Vue with Cypress
 

Recently uploaded

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 

Recently uploaded (20)

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 

Testing React Native Apps - Chain React 2023

  • 1. Testing React Native Apps As you get settled, write the answer to the following question on Post-It notes. Write as many answers on separates notes as you like. When you're done, put them on the back wall. What do you want to learn about testing in this workshop? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 2. Testing React Native Apps https://rnte.st/cr23 Clone the repo, build, and test! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 3. ReactNativeTesting.io Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 4. Josh Justice CodingItWrong.com Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 5. Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 6. Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 7. Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 8. Thank you, assistants! — David Leuiliette — Jon Major Condon Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 9. Answer the following two questions on Post-It notes. Then discuss your answers with your group. Choose someone who will summarize your group's answers to the whole workshop afterward. 1. What benefits are you currently getting from testing? 2. What are your testing pain points? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 10. Why Test? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 11. My Story Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 12. Testing Pain Points — Difficult to test — Flaky tests — Fragile tests Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 13. Example-Based Tests — Component tests (React Native Testing Library) — End-to-end tests (Detox) Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 14. Learning More Afterward — https://rnte.st/cr23 — Discord community Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 15. Questions and thoughts welcome! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 16. Stretch break! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 17. 02 Component Tests: Rendering Testing React Native Apps Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 18. What is a component test? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 19. React Native Testing Library @testing-library/react-native callstack.github.io/react-native-testing-library Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 20. What to test? — Call methods/functions? — Check state values? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 21. "We don’t encourage reading implementation details like state variables themselves…Instead, test observable behavior — i.e. what your component renders or does." -- @dan_abramov, 2019-03-06 tweet Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 22. Testing the Contract Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 23. "A component contract is the agreement between a component and the rest of the application." -- Edd Yerburgh, Testing Vue.js Applications Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 24. "Other components can assume the component will fulfill its contractual agreement and produce the agreed output if it’s provided the correct input." -- Edd Yerburgh, Testing Vue.js Applications Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 25. Discuss: What are some of the kinds of inputs and outputs that components have? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 26. Testing the Contract Inputs: — Props — User interaction events Outputs: — Rendered UI — Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 27. Testing the Contract Inputs: — Props — User interaction events Outputs: — Rendered UI — Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 28. To the code! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 29. Getter Functions — screen.getByText — screen.getByLabelText — screen.getByPlaceholderText Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 30. Text return <Text>Hello, world!</Text>; screen.getByText('Hello, world!') Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 31. TextInput return <TextInput placeholder="Enter your name" ... />; screen.getByPlaceholderText('Enter your name') Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 32. Image return ( <Image source={...} accessibilityLabel="squirrel waving" /> ); screen.getByLabelText('squirrel waving') Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 33. SVG import WavingHand from './assets/waving-hand.svg'; return <WavingHand accessibilityLabel="waving hand" />; screen.getByLabelText('waving hand') Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 34. Which Query Should I Use? callstack.github.io/react-native-testing-library/docs/how-should-i-query "your test should resemble how users interact with your code (component, page, etc.) as much as possible" Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 35. Which Query Should I Use? callstack.github.io/react-native-testing-library/docs/how-should-i-query Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 36. Note on getByRole() screen.getByRole('button', {name: 'Save Changes'}) — May become the top recommendation soon — Feature needed first: implicit roles (Pressables queryable as button by default) Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 37. Confirming Presence expect(screen.getBy…()).toBeVisible(); expect(screen.getBy…()).toBeOnTheScreen(); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 38. Confirming Absence expect(screen.queryBy…()).not.toBeOnTheScreen(); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 39. Getter Functions — screen.getByText — screen.getByLabelText — screen.getByPlaceholderText Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 40. Query Functions — screen.queryByText — screen.queryByLabelText — screen.queryByPlaceholderText Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 41. Testing the Contract Inputs: — Props — User interaction events Outputs: — Rendered UI — Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 42. Testing the Contract Inputs: — Props — User interaction events Outputs: ✅ Rendered UI - Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 43. Testing the Contract Inputs: — Props — User interaction events Outputs: ✅ Rendered UI - Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 44. To the code! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 45. Testing the Contract Inputs: — Props — User interaction events Outputs: ✅ Rendered UI - Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 46. Testing the Contract Inputs: ✅ Props - User interaction events Outputs: ✅ Rendered UI - Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 47. Exercise 1 — rn-testing-exercises — exercises/Exercise1.md For help: reactnativetesting.io/component/testing/ Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 48. A few more notes about testing rendering and props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 49. Testing content, not appearance. Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 50. What about snapshot tests? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 51. import renderer from 'react-test-renderer'; import Hello from './Hello'; it('renders correctly', () => { const tree = renderer.create(<Hello name="Josh" />).toJSON(); expect(tree).toMatchSnapshot(); }); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 52. 03 Component Tests: Actions and Mocks Testing React Native Apps Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 53. Testing the Contract Inputs: ✅ Props - User interaction events Outputs: ✅ Rendered UI - Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 54. Testing the Contract Inputs: ✅ Props - User interaction events Outputs: ✅ Rendered UI - Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 55. To the code! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 56. import {fireEvent, render, screen} from '@testing-library/react-native'; describe('NewMessageForm', () => { describe('pressing send', () => { it('clears the message field', () => { render(<NewMessageForm />); fireEvent.changeText( screen.getByPlaceholderText('Message'), 'Hello world', ); fireEvent.press(screen.getByText('Send')); expect(screen.getByPlaceholderText('Message')).toHaveProp('value', ''); }); }); }); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 57. fireEvent import {fireEvent} from '@testing-library/react-native'; fireEvent.press(element) fireEvent.changeText(element, text) fireEvent.scroll(element, eventData) fireEvent(element, eventName, eventData) Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 58. import {render, fireEvent} from '@testing-library/react-native'; describe('NewMessageForm', () => { describe('pressing send', () => { it('clears the message field', () => { render(<NewMessageForm />); fireEvent.changeText( screen.getByPlaceholderText('Message'), 'Hello world', ); fireEvent.press(screen.getByText('Send')); expect(screen.getByPlaceholderText('Message')).toHaveProp('value', ''); }); }); }); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 59. toHaveProp Provided by Jest Native expect(...).toHaveProp('propName', 'propValue'); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 60. Testing the Contract Inputs: ✅ Props - User interaction events Outputs: ✅ Rendered UI - Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 61. Testing the Contract Inputs: ✅ Props ✅ User interaction events Outputs: ✅ Rendered UI - Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 62. Testing the Contract Inputs: ✅ Props ✅ User interaction events Outputs: ✅ Rendered UI - Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 63. Mock Functions jestjs.io/docs/mock-functions Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 64. Creating a New Mock Function const myMock = jest.fn().mockName('myMock'); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 65. Mock Matchers expect(myMock).toHaveBeenCalled(); expect(myMock).toHaveBeenCalledWith(arg, secondArg, ...); expect(myMock).toHaveBeenCalledWith(expect.any(String)); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 66. To the code! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 67. it('calls the send handler', () => { const messageText = 'Hello world'; const sendHandler = jest.fn().mockName('sendHandler'); render(<NewMessageForm onSend={sendHandler} />); fireEvent.changeText( screen.getByPlaceholderText('Message'), messageText, ); fireEvent.press(screen.getByText('Send')); expect(sendHandler).toHaveBeenCalledWith(messageText); }); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 68. Question: Do you think mocks involve testing implementation details or not? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 69. My view: Mocks are an important part of testing the contract. Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 70. Testing the Contract Inputs: ✅ Props ✅ User interaction events Outputs: ✅ Rendered UI - Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 71. Testing the Contract Inputs: ✅ Props ✅ User interaction events Outputs: ✅ Rendered UI ✅ Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 72. Exercise 2 — rn-testing-exercises — exercises/Exercise2.md For help: reactnativetesting.io/component/testing/#interaction Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 73. Testing the Contract Inputs: — Props — User interaction events Outputs: — Rendered UI — Calls to function props Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 74. 04 Component Tests: Effects and Module Mocks Testing React Native Apps Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 75. How can we test effects? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 76. How can we test effects? Test the result/"effect". Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 77. Data loading effects hit the API Problem? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 78. Options for Mocking Web Service Requests Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 79. Options for Mocking Web Service Requests Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 80. Jest Module Mocks jestjs.io/docs/mock-functions#mocking-modules Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 81. To the code! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 82. import {render, screen} from '@testing-library/react-native'; import RestaurantContainer from './RestaurantContainer'; import api from './api'; jest.mock('./api'); describe('RestaurantContainer', () => { it('loads restaurants upon first render', async () => { api.get.mockResolvedValue({/* the response object */}); render(<RestaurantContainer />); expect(await screen.findByText('Pasta Place')).toBeVisible(); expect(screen.getByText('Salad Place')).toBeVisible(); expect(api.get).toHaveBeenCalledWith('/restaurants'); }); }); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 84. Getter Functions — screen.getByText — screen.getByLabelText — screen.getByPlaceholderText Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 85. Query Functions — screen.queryByText — screen.queryByLabelText — screen.queryByPlaceholderText Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 86. Find Functions — await screen.findByText — await screen.findByLabelText — await screen.findByPlaceholderText Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 87. Exercise 3 — rn-testing-exercises — exercises/Exercise3.md For help: reactnativetesting.io/component/testing Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 88. act() Error Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 89. To the code! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 90. Component Testing As a group, come up a way to explain what "testing the contract" of a component means to other developers. Use the poster in your area. You can write a bulleted list, use diagrams, draw a picture to use a metaphor, etc. Feel free to get creative! After, your group will present your board to the workshop. Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 91. 05 End-to-End Testing: Basics Testing React Native Apps Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 92. E2E Tests Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 93. Choosing an E2E Test Library Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 94. — Runs on Hardware — Runs on Sauce Labs and AWS Device Farm — Runs completely outside your app — Have to use multiple libraries together — Hard to find complete documentation — Tests tend to be flaky Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 95. Detox — Write tests in JavaScript or TypeScript — Has inside knowledge of your app — Expo not officially supported — Can be complex to set up — Does not run on physical iOS devices yet Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 96. Maestro — Easy setup, a single library — Runs completely outside your app — Maestro Studio to interactively write commands — New; rough edges Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 97. To the code! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 98. it('detects text', async () => { await expect(element(by.label('Hello, Lecture 5!'))).toBeVisible(); }); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 99. element(…) Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 100. it('should have welcome screen', async () => { await expect( element(by.label('Welcome to React Native!')) ).toBeVisible(); }); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 101. Matchers by.id() by.text() by.label() Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 102. await expect(element(by.id('welcome'))) .toBeVisible(); await expect(element(by.id('welcome'))) .toHaveText('Welcome to React Native!'); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 103. Expectations toExist() toBeVisible() toHaveText() toHaveValue() Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 104. To the code! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 105. await element(by.id('mybutton')).tap(); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 106. await element(by.id('mytextinput')) .typeText('I typed this'); await element(by.id('mytextinput')) .clearText(); await element(by.id('mytextinput')) .typeText('Something else'); await element(by.id('mytextinput')) .replaceText('Something else'); Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 107. Actions tap() typeText() clearText() replaceText() scroll() swipe() Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 108. What to E2E test? Main paths, not all edge cases Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 109. 06 End-to-End Testing: External Services Testing React Native Apps Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 110. Connecting to the real backend: Upsides? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 111. Connecting to the real backend: Downsides? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 112. Options for Mocking Web Service Requests Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 113. Local web server? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 114. Options for Mocking Web Service Requests Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 115. Fake Module Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 116. What's a fake? A version of the service that acts similar to the real thing but stores its data in-memory Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 117. To the code! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 118. API file setup api.js api.mock.js Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 119. api.js import axios from 'axios'; const api = axios.create({ baseURL: 'https://api.reactnativetesting.io', // other config }); export default api; Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 120. api.mock.js const api = { get() { return Promise.resolve({ data: [ {id: 1, name: 'Widget 1'}, {id: 2, name: 'Widget 2'}, ] }); }, // ... }; export default api; Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 121. Configure metro.config.js — Prefer .mock.js extension when present — Exact code may differ if you've modified metro.config.js for other reasons — E.g. using react-native-svg-transformer — See reactnativetesting.io/e2e/external-services Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 122. package.json "start": "react-native start", +"start:mock": "MOCK_API=true npm run start", "test": "jest" Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 123. For Windows support "start": "react-native start", +"start:mock": "cross-env MOCK_API=true npm run start", "test": "jest" Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 124. Exercise 4 — rn-testing-exercises — exercises/Exercise4.md For help: — reactnativetesting.io/e2e/testing Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 125. Recommendation: — Automate testing against a fake — Manually test integration with real service — If you need to automate testing with real service, do a small separate test suite Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 126. End-to-End Testing As a group, pick one of your group members' apps and come up with a list of the most valuable scenarios you would end-to-end test. Write each on a Post-It note and put it on your poster. If there are any you're uncertain how you would write a test for, discuss them as a group. Nominate someone to present your scenarios and questions to the whole workshop. Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 127. 07 Wrap-up Testing React Native Apps Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 128. How much of each type of test to do? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 129. Tradeoffs — End-to-End Tests: give confidence the whole app works — Unit and Component Tests: faster, easier, less flaky testing of edge cases, influence design of code Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 130. My Recommendations — End-to-end test main flows only — Component test edge cases — Extract plain functions and classes when it makes sense, and unit test them — Tweak as you go Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 131. To Discuss Write the answer to the following question on Post-It note. Use as many as you need: Based on what you learned today, what specifically do you want to do differently testing your React app going forward? Afterward we'll go around the room and each share our answers! Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 132. Remaining Questions? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 133. Remaining Questions? Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 134. Continuing the Learning — https://rnte.st/cr23 — https://reactnativetesting.io — Discord community Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 135. Effective Detox Testing Oct 25, 2023 -Virtual — CI on GitHub Actions — Detox local development workflow — When Detox vs RNTL vs manual — How much to test with Detox Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 136. Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 137. Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 138. Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23
  • 139. Thanks! https://rnte.st/cr23survey Josh Justice josh.justice@testdouble.com https://rnte.st/cr23 Testing React Native Apps - Josh Justice - Chain React - 2023-05-17 - https://rnte.st/cr23