Skip to content

Commit

Permalink
add checkbox unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lanchana committed Nov 16, 2021
1 parent ec86aac commit 2d97123
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 26 deletions.
14 changes: 0 additions & 14 deletions __tests__/App-test.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions __tests__/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import renderer from 'react-test-renderer';
import Checkbox from '../src/components/checkbox/Checkbox';
import { Text } from 'react-native';

it('renders correctly', () => {
const tree = renderer
.create(<Checkbox onPress={(): void => {}} checked={true}>
<Text>toggle</Text>
</Checkbox>)
.toJSON();
expect(tree).toMatchSnapshot();
});
75 changes: 75 additions & 0 deletions __tests__/__snapshots__/Checkbox.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
"borderColor": "transparent",
"borderRadius": 5,
"borderWidth": 1,
"height": 30,
"justifyContent": "center",
"transform": Array [
Object {
"scale": 1,
},
],
"width": 30,
}
}
>
<View
style={
Array [
Object {
"alignItems": "center",
"borderRadius": 20,
"height": 40,
"justifyContent": "center",
"width": 40,
},
Object {
"borderRadius": 5,
"height": 30,
"width": 30,
},
Object {
"backgroundColor": "#2240C4",
},
]
}
>
<View
checked={true}
style={
Array [
Object {
"borderColor": "#2240C4",
"borderRadius": 5,
"borderStyle": "solid",
"borderWidth": 1,
"bottom": 0,
"left": 0,
"position": "absolute",
"right": 0,
"top": 0,
},
]
}
/>
<svg
data-file-name="SvgCheck"
/>
</View>
</View>
`;
18 changes: 18 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
'preset': 'react-native',
'moduleFileExtensions': [
'ts',
'tsx',
'js',
'jsx',
'json',
'node'
],
'transformIgnorePatterns': [
'node_modules/(?!(@freakycoder|@react-native|react-native|rn-fetch|redux-persist-filesystem|@react-navigation' +
'|@react-native-community|react-navigation|react-navigation-redux-helpers|@sentry))'
],
'transform': {
'^.+\\.svg$': 'jest-svg-transformer'
}
};
15 changes: 3 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"android:build:debug": "./scripts/android-debug.sh",
"lint": "eslint --fix . --ext .js,.jsx,.ts,.tsx",
"postinstall": "./scripts/postinstall.sh",
"clean": "react-native-clean-project"
"clean": "react-native-clean-project",
"pod:install": "command -v pod && (cd ios/ && pod install && cd ..) || echo \"pod command not found\""
},
"dependencies": {
"@freakycoder/react-native-bounceable": "^0.2.5",
Expand Down Expand Up @@ -85,6 +86,7 @@
"babel-loader": "^8.2.3",
"eslint": "^7.14.0",
"jest": "^26.6.3",
"jest-svg-transformer": "^1.0.0",
"metro-react-native-babel-preset": "^0.64.0",
"react-dom": "17.0.1",
"react-native-clean-project": "^3.6.7",
Expand All @@ -96,17 +98,6 @@
"resolutions": {
"@types/react": "^17"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
},
"react-native": {
"crypto": "react-native-crypto",
"http": "@tradle/react-native-http",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7385,6 +7385,11 @@ jest-snapshot@^26.6.2:
pretty-format "^26.6.2"
semver "^7.3.2"

jest-svg-transformer@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/jest-svg-transformer/-/jest-svg-transformer-1.0.0.tgz#e38884ca4cd8b2295cdfa2a0b24667920c3a8a6d"
integrity sha1-44iEykzYsilc36KgskZnkgw6im0=

jest-util@^26.6.2:
version "26.6.2"
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-26.6.2.tgz#907535dbe4d5a6cb4c47ac9b926f6af29576cbc1"
Expand Down

0 comments on commit 2d97123

Please sign in to comment.