Skip to content

Commit

Permalink
Add basic unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
narin committed Jan 5, 2024
1 parent 7d01a73 commit 7f222ef
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 20 deletions.
3 changes: 3 additions & 0 deletions packages/components/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = {
},
],
},
moduleNameMapper: {
'\\.svg': '<rootDir>/jest/svgMock.ts',
},
setupFiles: [
'../../node_modules/react-native-gesture-handler/jestSetup.js',
'./jest/testSetup.ts',
Expand Down
2 changes: 2 additions & 0 deletions packages/components/jest/svgMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// __mocks__/svgMock.js
module.exports = 'SvgMock'
6 changes: 2 additions & 4 deletions packages/components/src/components/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Icon, IconProps, IconVariants } from './Icon'
import { Icon, IconProps } from './Icon'
import { Meta, StoryObj } from '@storybook/react-native'
import { View } from 'react-native'
import { generateDocs } from '../../utils/storybook'
Expand Down Expand Up @@ -38,8 +38,6 @@ export const _Primary: Story = {
width: 100,
height: 100,
fill: '#1e90ff',
name: 'HomeSelected',
preventScaling: true,
paddingTop: 50,
name: 'PaperClip',
},
}
17 changes: 17 additions & 0 deletions packages/components/src/components/Icon/Icon.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Icon } from './Icon'
import { RenderAPI, render } from '@testing-library/react-native'
import React from 'react'

describe('Icon', () => {
let component: RenderAPI

beforeEach(() => {
component = render(
<Icon name="HomeSelected" testID="myId" height={100} width={100} />,
)
})

it('initializes correctly', async () => {
expect(component).toBeTruthy()
})
})
32 changes: 16 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2916,7 +2916,7 @@ __metadata:
"@storybook/react": ^6.5.16
"@storybook/react-native": ^6.5.4
"@svgr/webpack": ^8.1.0
"@testing-library/react-native": ^12.3.0
"@testing-library/react-native": ^12.4.3
"@types/jest": ^29.5.3
"@types/react": ~18.2.14
"@types/react-test-renderer": ^18.0.1
Expand Down Expand Up @@ -6855,12 +6855,12 @@ __metadata:
languageName: node
linkType: hard

"@testing-library/react-native@npm:^12.3.0":
version: 12.3.0
resolution: "@testing-library/react-native@npm:12.3.0"
"@testing-library/react-native@npm:^12.4.3":
version: 12.4.3
resolution: "@testing-library/react-native@npm:12.4.3"
dependencies:
jest-matcher-utils: ^29.6.2
pretty-format: ^29.6.2
jest-matcher-utils: ^29.7.0
pretty-format: ^29.7.0
redent: ^3.0.0
peerDependencies:
jest: ">=28.0.0"
Expand All @@ -6870,7 +6870,7 @@ __metadata:
peerDependenciesMeta:
jest:
optional: true
checksum: 409b64207b4c7319926e5ce590adf84fe7ddb17ebdec4a92d4562c2ddcb3c23d7cf2ffd8f1810ab3241590817296b019869116f6d91f4125b452bb88c90e9031
checksum: bd1c06b200063ffad26245cbc61b7256b5bfcc2c69a32f7e6dc9ff1bf44c3743117d5010b8dbc8f9a1b660c3ee22ccf9ecc320c03db52f9ec75ba7e52c1d8ba3
languageName: node
linkType: hard

Expand Down Expand Up @@ -16005,7 +16005,7 @@ __metadata:
languageName: node
linkType: hard

"jest-matcher-utils@npm:^29.6.2, jest-matcher-utils@npm:^29.7.0":
"jest-matcher-utils@npm:^29.7.0":
version: 29.7.0
resolution: "jest-matcher-utils@npm:29.7.0"
dependencies:
Expand Down Expand Up @@ -20091,25 +20091,25 @@ __metadata:
languageName: node
linkType: hard

"pretty-format@npm:^29.6.2, pretty-format@npm:^29.7.0":
version: 29.7.0
resolution: "pretty-format@npm:29.7.0"
"pretty-format@npm:^29.6.3":
version: 29.6.3
resolution: "pretty-format@npm:29.6.3"
dependencies:
"@jest/schemas": ^29.6.3
ansi-styles: ^5.0.0
react-is: ^18.0.0
checksum: 032c1602383e71e9c0c02a01bbd25d6759d60e9c7cf21937dde8357aa753da348fcec5def5d1002c9678a8524d5fe099ad98861286550ef44de8808cc61e43b6
checksum: 4e1c0db48e65571c22e80ff92123925ff8b3a2a89b71c3a1683cfde711004d492de32fe60c6bc10eea8bf6c678e5cbe544ac6c56cb8096e1eb7caf856928b1c4
languageName: node
linkType: hard

"pretty-format@npm:^29.6.3":
version: 29.6.3
resolution: "pretty-format@npm:29.6.3"
"pretty-format@npm:^29.7.0":
version: 29.7.0
resolution: "pretty-format@npm:29.7.0"
dependencies:
"@jest/schemas": ^29.6.3
ansi-styles: ^5.0.0
react-is: ^18.0.0
checksum: 4e1c0db48e65571c22e80ff92123925ff8b3a2a89b71c3a1683cfde711004d492de32fe60c6bc10eea8bf6c678e5cbe544ac6c56cb8096e1eb7caf856928b1c4
checksum: 032c1602383e71e9c0c02a01bbd25d6759d60e9c7cf21937dde8357aa753da348fcec5def5d1002c9678a8524d5fe099ad98861286550ef44de8808cc61e43b6
languageName: node
linkType: hard

Expand Down

0 comments on commit 7f222ef

Please sign in to comment.