Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
jest-expo
Advanced tools
A [Jest](https://facebook.github.io/jest/) preset to painlessly test your Expo apps.
The jest-expo package is a set of Jest presets tailored for testing Expo applications. It simplifies the setup and configuration needed to test React Native components and other Expo-specific features, making it easier to write and run tests for Expo projects.
Preset Configuration
The jest-expo package provides a preset configuration that you can use in your Jest configuration file. This preset includes all necessary settings to test Expo applications, such as transforming JavaScript and TypeScript files, handling static assets, and mocking native modules.
module.exports = { preset: 'jest-expo' };
Snapshot Testing
Snapshot testing is a feature that allows you to capture the rendered output of a component and compare it to a reference snapshot file. This helps ensure that your UI does not change unexpectedly.
import React from 'react';
import renderer from 'react-test-renderer';
import App from '../App';
test('App snapshot', () => {
const tree = renderer.create(<App />).toJSON();
expect(tree).toMatchSnapshot();
});
Mocking Native Modules
jest-expo makes it easy to mock native modules and Expo-specific APIs, allowing you to test components that rely on these modules without needing a physical device or emulator.
jest.mock('expo-constants', () => ({
manifest: {
extra: {
apiUrl: 'https://api.example.com'
}
}
}));
react-native-testing-library is a popular library for testing React Native components. It provides utilities to render components, query elements, and simulate user interactions. Compared to jest-expo, it focuses more on testing the behavior of components rather than configuration and setup.
Enzyme is a JavaScript testing utility for React that makes it easier to assert, manipulate, and traverse your React components' output. While it is not specific to React Native or Expo, it can be used in conjunction with other tools to test React Native components. It offers a different approach to testing compared to jest-expo, focusing on shallow rendering and component manipulation.
Jest is a delightful JavaScript testing framework with a focus on simplicity. It works with projects using Babel, TypeScript, Node.js, React, Angular, Vue.js, and Svelte. While jest-expo is built on top of Jest and provides Expo-specific configurations, Jest itself is a more general-purpose testing framework.
A Jest preset to painlessly test your Expo apps.
yarn add jest-expo --dev
or npm i jest-expo --save-dev
Add the following config to package.json
:
"scripts": {
"test": "node_modules/jest/bin/jest.js"
},
"jest": {
"preset": "jest-expo"
}
Create a __tests__
directory anywhere you like and a Example-test.js
file inside of it, and add this code:
it('works', () => {
expect(1).toBe(1);
});
Run npm test
and it should pass
FAQs
A Jest preset to painlessly test your Expo / React Native apps.
The npm package jest-expo receives a total of 172,257 weekly downloads. As such, jest-expo popularity was classified as popular.
We found that jest-expo demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 28 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.