Skip to content

Instantly share code, notes, and snippets.

View janhesters's full-sized avatar
📈
Learning.

Jan Hesters janhesters

📈
Learning.
View GitHub Profile
# Jest
#
.jest/
coverage/
import Enzyme from "enzyme";
import Adapter from "enzyme-adapter-react-16";
global.fetch = require("jest-fetch-mock");
Enzyme.configure({ adapter: new Adapter() });
{
"extends": "./tsconfig",
"compilerOptions": {
"jsx": "react",
"module": "commonjs"
}
}
@janhesters
janhesters / package.json
Created September 16, 2018 18:44
Replace the existing `jest` key in the dictionary with this code.
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js",
"^.+\\.tsx?$": "ts-jest"
},
"globals": {
"ts-jest": {
"tsConfigFile": "tsconfig.jest.json"
}
import { AppRegistry } from "react-native";
import App from "./app/App";
import { name as appName } from "./app.json";
AppRegistry.registerComponent(appName, () => App);
import App from './App';
import { shallow, ShallowWrapper } from 'enzyme';
import React from 'react';
import { View } from 'react-native';
const createTestProps = (props: Object) => ({
...props
});
describe("App", () => {
{
"parser": "babel-eslint",
"env": {
"browser": true,
"jest": true
},
"plugins": ["react"],
"extends": ["eslint:recommended", "plugin:react/recommended"],
"rules": {},
"globals": {
// ... your other imports
import LocalizedStrings from 'react-native-localization';
let strings = new LocalizedStrings({
en: {
welcome: "Welcome to React Native!",
instructions: "To get started, edit App.tsx",
instructionsIOS: "Press Cmd+R to reload,\n" + "Cmd+D or shake for dev menu",
instructionsAndroid: "Double tap R on your keyboard to reload,\n" + "Shake or press menu button for dev menu"
},
const instructions = Platform.select({
ios: strings.instructionsIOS,
android: strings.instructionsAndroid
});
<View style={styles.container}>
<Text style={styles.welcome}>{strings.welcome}</Text>
<Text style={styles.instructions}>{strings.instructions}</Text>
<Text style={styles.instructions}>{instructions}</Text>
</View>