From 7f222ef5f761ffd8cb7de57916c93ec5bb4cb74b Mon Sep 17 00:00:00 2001 From: Narin Ratana Date: Thu, 4 Jan 2024 20:04:13 -0800 Subject: [PATCH] Add basic unit test --- packages/components/jest.config.js | 3 ++ packages/components/jest/svgMock.ts | 2 ++ .../src/components/Icon/Icon.stories.tsx | 6 ++-- .../src/components/Icon/Icon.test.tsx | 17 ++++++++++ yarn.lock | 32 +++++++++---------- 5 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 packages/components/jest/svgMock.ts create mode 100644 packages/components/src/components/Icon/Icon.test.tsx diff --git a/packages/components/jest.config.js b/packages/components/jest.config.js index b49a3948..f16b00a9 100644 --- a/packages/components/jest.config.js +++ b/packages/components/jest.config.js @@ -10,6 +10,9 @@ module.exports = { }, ], }, + moduleNameMapper: { + '\\.svg': '/jest/svgMock.ts', + }, setupFiles: [ '../../node_modules/react-native-gesture-handler/jestSetup.js', './jest/testSetup.ts', diff --git a/packages/components/jest/svgMock.ts b/packages/components/jest/svgMock.ts new file mode 100644 index 00000000..45a1ec09 --- /dev/null +++ b/packages/components/jest/svgMock.ts @@ -0,0 +1,2 @@ +// __mocks__/svgMock.js +module.exports = 'SvgMock' diff --git a/packages/components/src/components/Icon/Icon.stories.tsx b/packages/components/src/components/Icon/Icon.stories.tsx index 66ad6547..dd3a815c 100644 --- a/packages/components/src/components/Icon/Icon.stories.tsx +++ b/packages/components/src/components/Icon/Icon.stories.tsx @@ -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' @@ -38,8 +38,6 @@ export const _Primary: Story = { width: 100, height: 100, fill: '#1e90ff', - name: 'HomeSelected', - preventScaling: true, - paddingTop: 50, + name: 'PaperClip', }, } diff --git a/packages/components/src/components/Icon/Icon.test.tsx b/packages/components/src/components/Icon/Icon.test.tsx new file mode 100644 index 00000000..b2fb29dd --- /dev/null +++ b/packages/components/src/components/Icon/Icon.test.tsx @@ -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( + , + ) + }) + + it('initializes correctly', async () => { + expect(component).toBeTruthy() + }) +}) diff --git a/yarn.lock b/yarn.lock index f5ba24c6..3dacb10d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 @@ -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" @@ -6870,7 +6870,7 @@ __metadata: peerDependenciesMeta: jest: optional: true - checksum: 409b64207b4c7319926e5ce590adf84fe7ddb17ebdec4a92d4562c2ddcb3c23d7cf2ffd8f1810ab3241590817296b019869116f6d91f4125b452bb88c90e9031 + checksum: bd1c06b200063ffad26245cbc61b7256b5bfcc2c69a32f7e6dc9ff1bf44c3743117d5010b8dbc8f9a1b660c3ee22ccf9ecc320c03db52f9ec75ba7e52c1d8ba3 languageName: node linkType: hard @@ -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: @@ -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