SOC 직업 분류 기준
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/epam/deps-frontend --skill unit-tests명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SKILL.md 표시 중
| name | unit-tests |
| description | Rules for writing unit tests |
.test.js extension alongside the source filesComponentName.test.js for ComponentName.jsxContainerName.test.js for ContainerName.jsxrequire, use import at the top of the test filelocalize(Localization.KEY)) instead of hardcoded strings when testing text content that uses localization in the componentFollow this import order:
@/mocks/*) - including mockUuid when testing components that generate IDs@testing-library/*, enzyme, jest)@/*) - including { Localization, localize } from '@/localization/i18n' when testing localized textExample with all common imports:
import { mockEnv } from '@/mocks/mockEnv'
import { mockReactHookForm } from '@/mocks/mockReactHookForm'
import { mockUuid } from '@/mocks/mockUuid'
import { screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Localization, localize } from '@/localization/i18n'
import { render } from '@/utils/rendererRTL'
import { ComponentName } from './ComponentName'
jest.mock('@/utils/env', () => mockEnv)
jest.mock('react-hook-form', () => mockReactHookForm)
jest.mock('uuid', () => mockUuid)
import { mockEnv } from '@/mocks/mockEnv'
import { mockReactRedux } from '@/mocks/mockReactRedux'
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import flushPromises from 'flush-promises'
import { Localization, localize } from '@/localization/i18n'
import { render } from '@/utils/rendererRTL'
// ... other imports
jest.mock('@/utils/env', () => mockEnv)
jest.mock('react-redux', () => mockReactRedux)
beforeEach(() => {
jest.clearAllMocks()
defaultProps = {
// ... props
}
})
test('renders correctly when {if case}', () => {
// test implementation
})
render from '@/utils/rendererRTL' for component unit tests@testing-library/react for integration teststoMatchSnapshot() for layout testingdescribe blocktest block instead of itactmapStateToProps and mapDispatchToProps separatelyrender from @/utils/rendererRTL for integration testingjest.mock()flush-promises for async operations if neededconst mockFunction = jest.fn(() => ({
unwrap: jest.fn(() => Promise.resolve(mockData))
}))
jest.mock('@/api/someApi', () => ({
someApiFunction: mockFunction
}))
@/utils/env with mockEnvmockReactRedux for action testingmockNotificationmockShallowComponent and its getPropsmockUuid from @/mocks/mockUuid for predictable IDs in testsWhen testing components that generate IDs using uuid, mock it for predictable test results:
import { mockUuid } from '@/mocks/mockUuid'
jest.mock('uuid', () => mockUuid)
test('creates object with predictable ID', () => {
// First call returns '1', second returns '2', etc.
const result = createObject()
expect(result.id).toBe('1')
})
Note: mockUuid generates sequential IDs ('1', '2', '3', etc.) across all tests in a file. Account for this when writing assertions.
// Mock selectors
jest.mock('@/selectors/someSelector', () => ({
someSelector: jest.fn(() => mockData)
}))
// Mock actions
jest.mock('@/actions/someAction', () => ({
someAction: jest.fn(() => ({ type: 'SOME_ACTION' }))
}))
// Mock external components
jest.mock('@/components/SomeComponent', () => ({
SomeComponent: jest.fn(() => <div>Mocked Component</div>)
}))
var MockTableLayout
jest.mock('./ParagraphLayout', () => mockShallowComponent('ParagraphLayout'))
jest.mock('./TableLayout', () => {
const mock = mockShallowComponent('TableLayout')
MockTableLayout = mock.TableLayout
return mock
})
test('displays error message when API call fails')test('disables submit button when form is invalid')test('calls add function when form is submitted')test('dispatches action when user clicks button')Good test names:
test('renders secondary button with icon and drawer is not visible initially')
test('submits form and creates Field instance with correct values')
test('does not call add function when cancel button is clicked')
test('closes drawer after successful form submission')
Bad test names:
test('works')
test('renders correctly')
test('button test')
test('form submission')
toBe(), toEqual(), toContain()expect.any() for type checking of FunctionstoEqual() for complete object verification over partial matchesmock.calls[0][0] or mock.lastCall[0]toHaveBeenNthCalledWith(n, ...args) to verify exact arguments passed to mocksmockUuid from @/mocks/mockUuidExample - INCORRECT (accessing mock internals):
const fieldInstance = defaultProps.add.mock.calls[0][0]
expect(fieldInstance.name).toBe('Test Field')
expect(fieldInstance.id).toBeDefined()
Example - CORRECT (using toHaveBeenNthCalledWith with mocked UUID):
import { mockUuid } from '@/mocks/mockUuid'
jest.mock('uuid', () => mockUuid)
test('submits form with correct values', async () => {
await user.click(submitButton)
expect(defaultProps.add).toHaveBeenCalledTimes(1)
expect(defaultProps.add).toHaveBeenNthCalledWith(1, {
id: '1',
name: 'Test Field',
fieldType: 'string',
extractorId: 'test-extractor-id',
value: '',
})
})
Example - For behavior-only testing (when exact arguments don't matter):
test('calls add function when form is submitted', async () => {
await user.click(submitButton)
expect(defaultProps.add).toHaveBeenCalledTimes(1)
})
async/await for async operationsflush-promises when neededwaitFor() from React Testing Library for async UI updatesscreen from '@testing-library/react'userEvent from @testing-library/user-eventlocalize(Localization.KEY) instead of hardcoded strings when testing text that uses localization in the component{ Localization, localize } from @/localization/i18n in test filesExample - INCORRECT:
test('renders button with label', () => {
render(<MyButton />)
expect(screen.getByRole('button')).toHaveTextContent('Submit')
})
Example - CORRECT:
import { Localization, localize } from '@/localization/i18n'
test('renders button with label', () => {
render(<MyButton />)
expect(screen.getByRole('button')).toHaveTextContent(localize(Localization.SUBMIT))
})
Example - Finding elements with localized text:
// Find button by localized text
const submitButton = buttons.find((btn) => btn.textContent === localize(Localization.SUBMIT))
// Assert text content
expect(element).toHaveTextContent(localize(Localization.ADD_FIELD))
Tests automatically inherit these rules from the project configuration:
testing-library/await-async-query: "error"testing-library/no-await-sync-query: "error"testing-library/no-debugging-utils: "warn"testing-library/no-node-access: "warn"react/prop-types: "off" (in test files)yarn test:manual - Run tests in watch modeyarn test:auto - Run all tests with coverageyarn test:ci - Run tests in CI environmentyarn test:debug - Run tests with debugger supportTo run a specific test file, use the following command:
cd /Users/Dzmitry_Astraukh/Documents/Repos/deps-frontend && node --trace-warnings --unhandled-rejections=strict ./node_modules/jest/bin/jest.js --colors --expand --errorOnDeprecated --config ./config/jest.config.js {fileName}
Replace {fileName} with the test filename or file path. You can use either:
ComponentName.test.jssrc/containers/ComponentName/ComponentName.test.jsExamples:
cd /Users/Dzmitry_Astraukh/Documents/Repos/deps-frontend && node --trace-warnings --unhandled-rejections=strict ./node_modules/jest/bin/jest.js --colors --expand --errorOnDeprecated --config ./config/jest.config.js KeyValuePairInsightsComparison.test.js
cd /Users/Dzmitry_Astraukh/Documents/Repos/deps-frontend && node --trace-warnings --unhandled-rejections=strict ./node_modules/jest/bin/jest.js --colors --expand --errorOnDeprecated --config ./config/jest.config.js src/containers/PromptCalibrationStudio/AddFieldDrawer/AddFieldDrawer.test.js
Note: The command includes cd to the project directory to ensure tests run with correct context. When running from terminal, use required_permissions: ["all"] to avoid sandbox restrictions.
// Use models for creating mock data
const mockDocument = new Document({
id: 'mock-id',
name: 'Mock Document',
status: DocumentStatus.PROCESSING
})
// Use selectors for mock data
const mockSelectorData = {
documents: [mockDocument],
loading: false,
error: null
}
beforeEach for common setupjest.clearAllMocks() if needed