@codyswann/lisa 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +867 -0
- package/all/copy-overwrite/.claude/README.md +205 -0
- package/all/copy-overwrite/.claude/agents/agent-architect.md +311 -0
- package/all/copy-overwrite/.claude/agents/codebase-analyzer.md +146 -0
- package/all/copy-overwrite/.claude/agents/codebase-locator.md +125 -0
- package/all/copy-overwrite/.claude/agents/codebase-pattern-finder.md +237 -0
- package/all/copy-overwrite/.claude/agents/git-history-analyzer.md +183 -0
- package/all/copy-overwrite/.claude/agents/hooks-expert.md +74 -0
- package/all/copy-overwrite/.claude/agents/skill-evaluator.md +246 -0
- package/all/copy-overwrite/.claude/agents/slash-command-architect.md +87 -0
- package/all/copy-overwrite/.claude/agents/web-search-researcher.md +112 -0
- package/all/copy-overwrite/.claude/commands/git/commit-and-submit-pr.md +8 -0
- package/all/copy-overwrite/.claude/commands/git/commit.md +44 -0
- package/all/copy-overwrite/.claude/commands/git/prune.md +34 -0
- package/all/copy-overwrite/.claude/commands/git/submit-pr.md +50 -0
- package/all/copy-overwrite/.claude/commands/jira/create.md +50 -0
- package/all/copy-overwrite/.claude/commands/jira/verify.md +34 -0
- package/all/copy-overwrite/.claude/commands/project/archive.md +8 -0
- package/all/copy-overwrite/.claude/commands/project/bootstrap.md +49 -0
- package/all/copy-overwrite/.claude/commands/project/complete-task.md +7 -0
- package/all/copy-overwrite/.claude/commands/project/debrief.md +65 -0
- package/all/copy-overwrite/.claude/commands/project/execute.md +94 -0
- package/all/copy-overwrite/.claude/commands/project/implement.md +42 -0
- package/all/copy-overwrite/.claude/commands/project/local-code-review.md +88 -0
- package/all/copy-overwrite/.claude/commands/project/lower-code-complexity.md +74 -0
- package/all/copy-overwrite/.claude/commands/project/plan.md +314 -0
- package/all/copy-overwrite/.claude/commands/project/research.md +248 -0
- package/all/copy-overwrite/.claude/commands/project/review.md +63 -0
- package/all/copy-overwrite/.claude/commands/project/setup.md +19 -0
- package/all/copy-overwrite/.claude/commands/project/verify.md +38 -0
- package/all/copy-overwrite/.claude/commands/pull-request/review.md +12 -0
- package/all/copy-overwrite/.claude/commands/rules/format-md.md +72 -0
- package/all/copy-overwrite/.claude/commands/sonarqube/check.md +6 -0
- package/all/copy-overwrite/.claude/commands/sonarqube/fix.md +3 -0
- package/all/copy-overwrite/.claude/hooks/README.md +301 -0
- package/all/copy-overwrite/.claude/hooks/notify-ntfy.sh +181 -0
- package/all/copy-overwrite/.claude/settings.json +41 -0
- package/all/copy-overwrite/.claude/settings.local.json.example +14 -0
- package/all/copy-overwrite/.claude/skills/coding-philosophy/SKILL.md +405 -0
- package/all/copy-overwrite/.claude/skills/coding-philosophy/references/function-structure.md +416 -0
- package/all/copy-overwrite/.claude/skills/coding-philosophy/references/immutable-patterns.md +316 -0
- package/all/copy-overwrite/.claude/skills/prompt-complexity-scorer/SKILL.md +118 -0
- package/all/copy-overwrite/.claude/skills/skill-creator/LICENSE.txt +202 -0
- package/all/copy-overwrite/.claude/skills/skill-creator/SKILL.md +210 -0
- package/all/copy-overwrite/.claude/skills/skill-creator/scripts/__pycache__/quick_validate.cpython-312.pyc +0 -0
- package/all/copy-overwrite/.claude/skills/skill-creator/scripts/init_skill.py +303 -0
- package/all/copy-overwrite/.claude/skills/skill-creator/scripts/package_skill.py +110 -0
- package/all/copy-overwrite/.claude/skills/skill-creator/scripts/quick_validate.py +65 -0
- package/all/copy-overwrite/CLAUDE.md +77 -0
- package/all/copy-overwrite/HUMAN.md +17 -0
- package/all/copy-overwrite/specs/.keep +0 -0
- package/all/create-only/PROJECT_RULES.md +0 -0
- package/cdk/merge/package.json +20 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +107 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/prompts.d.ts +45 -0
- package/dist/cli/prompts.d.ts.map +1 -0
- package/dist/cli/prompts.js +58 -0
- package/dist/cli/prompts.js.map +1 -0
- package/dist/core/config.d.ts +73 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +36 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/lisa.d.ts +81 -0
- package/dist/core/lisa.d.ts.map +1 -0
- package/dist/core/lisa.js +459 -0
- package/dist/core/lisa.js.map +1 -0
- package/dist/core/manifest.d.ts +58 -0
- package/dist/core/manifest.d.ts.map +1 -0
- package/dist/core/manifest.js +104 -0
- package/dist/core/manifest.js.map +1 -0
- package/dist/detection/detector.interface.d.ts +15 -0
- package/dist/detection/detector.interface.d.ts.map +1 -0
- package/dist/detection/detector.interface.js +2 -0
- package/dist/detection/detector.interface.js.map +1 -0
- package/dist/detection/detectors/cdk.d.ts +10 -0
- package/dist/detection/detectors/cdk.d.ts.map +1 -0
- package/dist/detection/detectors/cdk.js +34 -0
- package/dist/detection/detectors/cdk.js.map +1 -0
- package/dist/detection/detectors/expo.d.ts +10 -0
- package/dist/detection/detectors/expo.d.ts.map +1 -0
- package/dist/detection/detectors/expo.js +30 -0
- package/dist/detection/detectors/expo.js.map +1 -0
- package/dist/detection/detectors/nestjs.d.ts +10 -0
- package/dist/detection/detectors/nestjs.d.ts.map +1 -0
- package/dist/detection/detectors/nestjs.js +34 -0
- package/dist/detection/detectors/nestjs.js.map +1 -0
- package/dist/detection/detectors/npm-package.d.ts +13 -0
- package/dist/detection/detectors/npm-package.d.ts.map +1 -0
- package/dist/detection/detectors/npm-package.js +30 -0
- package/dist/detection/detectors/npm-package.js.map +1 -0
- package/dist/detection/detectors/typescript.d.ts +10 -0
- package/dist/detection/detectors/typescript.d.ts.map +1 -0
- package/dist/detection/detectors/typescript.js +25 -0
- package/dist/detection/detectors/typescript.js.map +1 -0
- package/dist/detection/index.d.ts +24 -0
- package/dist/detection/index.d.ts.map +1 -0
- package/dist/detection/index.js +57 -0
- package/dist/detection/index.js.map +1 -0
- package/dist/errors/index.d.ts +69 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +110 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/console-logger.d.ts +12 -0
- package/dist/logging/console-logger.d.ts.map +1 -0
- package/dist/logging/console-logger.js +22 -0
- package/dist/logging/console-logger.js.map +1 -0
- package/dist/logging/index.d.ts +4 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +3 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.interface.d.ts +20 -0
- package/dist/logging/logger.interface.d.ts.map +1 -0
- package/dist/logging/logger.interface.js +2 -0
- package/dist/logging/logger.interface.js.map +1 -0
- package/dist/logging/silent-logger.d.ts +12 -0
- package/dist/logging/silent-logger.d.ts.map +1 -0
- package/dist/logging/silent-logger.js +21 -0
- package/dist/logging/silent-logger.js.map +1 -0
- package/dist/strategies/copy-contents.d.ts +14 -0
- package/dist/strategies/copy-contents.d.ts.map +1 -0
- package/dist/strategies/copy-contents.js +69 -0
- package/dist/strategies/copy-contents.js.map +1 -0
- package/dist/strategies/copy-overwrite.d.ts +14 -0
- package/dist/strategies/copy-overwrite.d.ts.map +1 -0
- package/dist/strategies/copy-overwrite.js +47 -0
- package/dist/strategies/copy-overwrite.js.map +1 -0
- package/dist/strategies/create-only.d.ts +13 -0
- package/dist/strategies/create-only.d.ts.map +1 -0
- package/dist/strategies/create-only.js +30 -0
- package/dist/strategies/create-only.js.map +1 -0
- package/dist/strategies/index.d.ts +31 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/index.js +52 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/strategies/merge.d.ts +13 -0
- package/dist/strategies/merge.d.ts.map +1 -0
- package/dist/strategies/merge.js +60 -0
- package/dist/strategies/merge.js.map +1 -0
- package/dist/strategies/strategy.interface.d.ts +31 -0
- package/dist/strategies/strategy.interface.d.ts.map +1 -0
- package/dist/strategies/strategy.interface.js +2 -0
- package/dist/strategies/strategy.interface.js.map +1 -0
- package/dist/transaction/backup.d.ts +38 -0
- package/dist/transaction/backup.d.ts.map +1 -0
- package/dist/transaction/backup.js +97 -0
- package/dist/transaction/backup.js.map +1 -0
- package/dist/transaction/index.d.ts +4 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/index.js +3 -0
- package/dist/transaction/index.js.map +1 -0
- package/dist/transaction/transaction.d.ts +34 -0
- package/dist/transaction/transaction.d.ts.map +1 -0
- package/dist/transaction/transaction.js +68 -0
- package/dist/transaction/transaction.js.map +1 -0
- package/dist/utils/file-operations.d.ts +29 -0
- package/dist/utils/file-operations.d.ts.map +1 -0
- package/dist/utils/file-operations.js +84 -0
- package/dist/utils/file-operations.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/json-utils.d.ts +22 -0
- package/dist/utils/json-utils.d.ts.map +1 -0
- package/dist/utils/json-utils.js +57 -0
- package/dist/utils/json-utils.js.map +1 -0
- package/dist/utils/path-utils.d.ts +21 -0
- package/dist/utils/path-utils.d.ts.map +1 -0
- package/dist/utils/path-utils.js +35 -0
- package/dist/utils/path-utils.js.map +1 -0
- package/eslint-plugin-code-organization/README.md +149 -0
- package/eslint-plugin-code-organization/__tests__/enforce-statement-order.test.js +468 -0
- package/eslint-plugin-code-organization/index.js +23 -0
- package/eslint-plugin-code-organization/package.json +10 -0
- package/eslint-plugin-code-organization/rules/enforce-statement-order.js +157 -0
- package/expo/copy-overwrite/.claude/skills/apollo-client/SKILL.md +238 -0
- package/expo/copy-overwrite/.claude/skills/apollo-client/references/mutation-patterns.md +360 -0
- package/expo/copy-overwrite/.claude/skills/atomic-design-gluestack/SKILL.md +360 -0
- package/expo/copy-overwrite/.claude/skills/atomic-design-gluestack/references/atomic-levels.md +417 -0
- package/expo/copy-overwrite/.claude/skills/atomic-design-gluestack/references/folder-structure.md +257 -0
- package/expo/copy-overwrite/.claude/skills/atomic-design-gluestack/references/gluestack-mapping.md +233 -0
- package/expo/copy-overwrite/.claude/skills/atomic-design-gluestack/scripts/validate_atomic_structure.py +327 -0
- package/expo/copy-overwrite/.claude/skills/container-view-pattern/SKILL.md +299 -0
- package/expo/copy-overwrite/.claude/skills/container-view-pattern/references/examples.md +749 -0
- package/expo/copy-overwrite/.claude/skills/container-view-pattern/references/patterns.md +318 -0
- package/expo/copy-overwrite/.claude/skills/container-view-pattern/scripts/create_component.py +198 -0
- package/expo/copy-overwrite/.claude/skills/container-view-pattern/scripts/validate_component.py +207 -0
- package/expo/copy-overwrite/.claude/skills/cross-platform-compatibility/SKILL.md +268 -0
- package/expo/copy-overwrite/.claude/skills/cross-platform-compatibility/references/common-issues.md +619 -0
- package/expo/copy-overwrite/.claude/skills/cross-platform-compatibility/references/file-extensions.md +340 -0
- package/expo/copy-overwrite/.claude/skills/cross-platform-compatibility/references/platform-api.md +276 -0
- package/expo/copy-overwrite/.claude/skills/cross-platform-compatibility/scripts/validate_cross_platform.py +414 -0
- package/expo/copy-overwrite/.claude/skills/directory-structure/SKILL.md +202 -0
- package/expo/copy-overwrite/.claude/skills/directory-structure/scripts/validate_structure.py +443 -0
- package/expo/copy-overwrite/.claude/skills/expo-env-config/SKILL.md +309 -0
- package/expo/copy-overwrite/.claude/skills/expo-env-config/references/validation-patterns.md +417 -0
- package/expo/copy-overwrite/.claude/skills/expo-router-best-practices/SKILL.md +431 -0
- package/expo/copy-overwrite/.claude/skills/expo-router-best-practices/references/official-docs.md +290 -0
- package/expo/copy-overwrite/.claude/skills/expo-router-best-practices/scripts/generate-route.py +169 -0
- package/expo/copy-overwrite/.claude/skills/gluestack-nativewind/SKILL.md +411 -0
- package/expo/copy-overwrite/.claude/skills/gluestack-nativewind/references/color-tokens.md +343 -0
- package/expo/copy-overwrite/.claude/skills/gluestack-nativewind/references/component-mapping.md +307 -0
- package/expo/copy-overwrite/.claude/skills/gluestack-nativewind/references/spacing-scale.md +300 -0
- package/expo/copy-overwrite/.claude/skills/gluestack-nativewind/scripts/validate_styling.py +354 -0
- package/expo/copy-overwrite/.claude/skills/local-state/SKILL.md +362 -0
- package/expo/copy-overwrite/.claude/skills/local-state/references/async-storage.md +505 -0
- package/expo/copy-overwrite/.claude/skills/local-state/references/persistence-patterns.md +711 -0
- package/expo/copy-overwrite/.claude/skills/local-state/references/reactive-variables.md +446 -0
- package/expo/copy-overwrite/.claude/skills/playwright-selectors/SKILL.md +223 -0
- package/expo/copy-overwrite/.claude/skills/testing-library/SKILL.md +319 -0
- package/expo/copy-overwrite/.claude/skills/testing-library/references/async-patterns.md +420 -0
- package/expo/copy-overwrite/.claude/skills/testing-library/references/expo-router-testing.md +556 -0
- package/expo/copy-overwrite/.claude/skills/testing-library/references/mocking-patterns.md +590 -0
- package/expo/copy-overwrite/.claude/skills/testing-library/references/query-priority.md +291 -0
- package/expo/copy-overwrite/.easignore.extra +2 -0
- package/expo/copy-overwrite/.mcp.json +33 -0
- package/expo/copy-overwrite/eslint-plugin-component-structure/README.md +234 -0
- package/expo/copy-overwrite/eslint-plugin-component-structure/__tests__/plugin-index.test.js +84 -0
- package/expo/copy-overwrite/eslint-plugin-component-structure/__tests__/require-memo-in-view.test.js +196 -0
- package/expo/copy-overwrite/eslint-plugin-component-structure/__tests__/single-component-per-file.test.js +289 -0
- package/expo/copy-overwrite/eslint-plugin-component-structure/index.js +32 -0
- package/expo/copy-overwrite/eslint-plugin-component-structure/package.json +10 -0
- package/expo/copy-overwrite/eslint-plugin-component-structure/rules/enforce-component-structure.js +230 -0
- package/expo/copy-overwrite/eslint-plugin-component-structure/rules/no-return-in-view.js +91 -0
- package/expo/copy-overwrite/eslint-plugin-component-structure/rules/require-memo-in-view.js +178 -0
- package/expo/copy-overwrite/eslint-plugin-component-structure/rules/single-component-per-file.js +238 -0
- package/expo/copy-overwrite/eslint-plugin-ui-standards/README.md +260 -0
- package/expo/copy-overwrite/eslint-plugin-ui-standards/index.js +29 -0
- package/expo/copy-overwrite/eslint-plugin-ui-standards/package.json +10 -0
- package/expo/copy-overwrite/eslint-plugin-ui-standards/rules/no-classname-outside-ui.js +51 -0
- package/expo/copy-overwrite/eslint-plugin-ui-standards/rules/no-direct-rn-imports.js +55 -0
- package/expo/copy-overwrite/eslint-plugin-ui-standards/rules/no-inline-styles.js +73 -0
- package/expo/copy-overwrite/eslint.config.mjs +560 -0
- package/expo/copy-overwrite/lighthouserc.js +194 -0
- package/expo/create-only/lighthouserc-config.json +28 -0
- package/expo/merge/package.json +132 -0
- package/lisa.sh +35 -0
- package/nestjs/copy-overwrite/.claude/skills/nestjs-graphql/SKILL.md +176 -0
- package/nestjs/copy-overwrite/.claude/skills/nestjs-graphql/references/advanced-features.md +527 -0
- package/nestjs/copy-overwrite/.claude/skills/nestjs-graphql/references/project-patterns.md +483 -0
- package/nestjs/copy-overwrite/.claude/skills/nestjs-graphql/references/quick-start.md +257 -0
- package/nestjs/copy-overwrite/.claude/skills/nestjs-graphql/references/resolvers-mutations.md +413 -0
- package/nestjs/copy-overwrite/.claude/skills/nestjs-graphql/references/types-scalars.md +513 -0
- package/nestjs/copy-overwrite/.claude/skills/nestjs-rules/SKILL.md +536 -0
- package/nestjs/copy-overwrite/.claude/skills/typeorm-patterns/SKILL.md +275 -0
- package/nestjs/copy-overwrite/.claude/skills/typeorm-patterns/references/configuration-patterns.md +487 -0
- package/nestjs/copy-overwrite/.claude/skills/typeorm-patterns/references/entity-patterns.md +450 -0
- package/nestjs/copy-overwrite/.claude/skills/typeorm-patterns/references/observability-patterns.md +536 -0
- package/nestjs/merge/package.json +75 -0
- package/package.json +124 -0
- package/typescript/copy-contents/.husky/commit-msg +91 -0
- package/typescript/copy-contents/.husky/pre-commit +96 -0
- package/typescript/copy-contents/.husky/pre-push +211 -0
- package/typescript/copy-overwrite/.claude/hooks/format-on-edit.sh +74 -0
- package/typescript/copy-overwrite/.claude/hooks/install_pkgs.sh +59 -0
- package/typescript/copy-overwrite/.claude/hooks/lint-on-edit.sh +103 -0
- package/typescript/copy-overwrite/.claude/skills/jsdoc-best-practices/SKILL.md +388 -0
- package/typescript/copy-overwrite/.github/README.md +455 -0
- package/typescript/copy-overwrite/.github/dependabot.yml +40 -0
- package/typescript/copy-overwrite/.github/k6/BROWSER_TESTING_NOTE.md +129 -0
- package/typescript/copy-overwrite/.github/k6/INTEGRATION_GUIDE.md +354 -0
- package/typescript/copy-overwrite/.github/k6/README.md +386 -0
- package/typescript/copy-overwrite/.github/k6/SCENARIO_SELECTION_GUIDE.md +264 -0
- package/typescript/copy-overwrite/.github/k6/examples/customer-deploy-integration.yml +115 -0
- package/typescript/copy-overwrite/.github/k6/examples/data-driven-test.js +268 -0
- package/typescript/copy-overwrite/.github/k6/scenarios/load.js +142 -0
- package/typescript/copy-overwrite/.github/k6/scenarios/load.json +27 -0
- package/typescript/copy-overwrite/.github/k6/scenarios/smoke.js +26 -0
- package/typescript/copy-overwrite/.github/k6/scenarios/smoke.json +20 -0
- package/typescript/copy-overwrite/.github/k6/scenarios/soak.js +244 -0
- package/typescript/copy-overwrite/.github/k6/scenarios/soak.json +29 -0
- package/typescript/copy-overwrite/.github/k6/scenarios/spike.js +180 -0
- package/typescript/copy-overwrite/.github/k6/scenarios/spike.json +32 -0
- package/typescript/copy-overwrite/.github/k6/scenarios/stress.js +206 -0
- package/typescript/copy-overwrite/.github/k6/scenarios/stress.json +38 -0
- package/typescript/copy-overwrite/.github/k6/scripts/api-test.js +452 -0
- package/typescript/copy-overwrite/.github/k6/scripts/default-test.js +185 -0
- package/typescript/copy-overwrite/.github/k6/thresholds/normal.json +30 -0
- package/typescript/copy-overwrite/.github/k6/thresholds/relaxed.json +21 -0
- package/typescript/copy-overwrite/.github/k6/thresholds/strict.json +29 -0
- package/typescript/copy-overwrite/.github/workflows/build.yml +72 -0
- package/typescript/copy-overwrite/.github/workflows/ci.yml +49 -0
- package/typescript/copy-overwrite/.github/workflows/claude.yml +51 -0
- package/typescript/copy-overwrite/.github/workflows/create-github-issue-on-failure.yml +113 -0
- package/typescript/copy-overwrite/.github/workflows/create-jira-issue-on-failure.yml +195 -0
- package/typescript/copy-overwrite/.github/workflows/create-sentry-issue-on-failure.yml +267 -0
- package/typescript/copy-overwrite/.github/workflows/deploy.yml +228 -0
- package/typescript/copy-overwrite/.github/workflows/k6-load-test-README.md +230 -0
- package/typescript/copy-overwrite/.github/workflows/lighthouse.yml +68 -0
- package/typescript/copy-overwrite/.github/workflows/load-test.yml +282 -0
- package/typescript/copy-overwrite/.github/workflows/quality.yml +1737 -0
- package/typescript/copy-overwrite/.github/workflows/release.yml +1599 -0
- package/typescript/copy-overwrite/.gitleaksignore +28 -0
- package/typescript/copy-overwrite/.nvmrc +1 -0
- package/typescript/copy-overwrite/.prettierignore +23 -0
- package/typescript/copy-overwrite/.prettierrc.json +22 -0
- package/typescript/copy-overwrite/.versionrc +42 -0
- package/typescript/copy-overwrite/.yamllint +20 -0
- package/typescript/copy-overwrite/commitlint.config.js +11 -0
- package/typescript/copy-overwrite/eslint-plugin-code-organization/README.md +149 -0
- package/typescript/copy-overwrite/eslint-plugin-code-organization/__tests__/enforce-statement-order.test.js +468 -0
- package/typescript/copy-overwrite/eslint-plugin-code-organization/index.js +23 -0
- package/typescript/copy-overwrite/eslint-plugin-code-organization/package.json +10 -0
- package/typescript/copy-overwrite/eslint-plugin-code-organization/rules/enforce-statement-order.js +157 -0
- package/typescript/copy-overwrite/eslint.config.mjs +390 -0
- package/typescript/copy-overwrite/eslint.ignore.config.json +57 -0
- package/typescript/copy-overwrite/eslint.thresholds.config.json +5 -0
- package/typescript/github-rulesets/base.json +106 -0
- package/typescript/merge/.claude/settings.json +28 -0
- package/typescript/merge/package.json +71 -0
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
# Mocking Patterns
|
|
2
|
+
|
|
3
|
+
This reference covers common mocking patterns for Expo and React Native testing.
|
|
4
|
+
|
|
5
|
+
## Global Setup Mocks
|
|
6
|
+
|
|
7
|
+
Place these in `jest/setup-jest.ts` or your Jest setup file.
|
|
8
|
+
|
|
9
|
+
### AsyncStorage
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
jest.mock("@react-native-async-storage/async-storage", () =>
|
|
13
|
+
require("@react-native-async-storage/async-storage/jest/async-storage-mock")
|
|
14
|
+
);
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Expo Fonts
|
|
18
|
+
|
|
19
|
+
Prevents async loading issues with icon fonts:
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
jest.mock("expo-font", () => ({
|
|
23
|
+
...jest.requireActual("expo-font"),
|
|
24
|
+
isLoaded: jest.fn(() => true),
|
|
25
|
+
loadAsync: jest.fn(() => Promise.resolve()),
|
|
26
|
+
}));
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Expo Constants
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
jest.mock("expo-constants", () => ({
|
|
33
|
+
...jest.requireActual("expo-constants"),
|
|
34
|
+
expoConfig: {
|
|
35
|
+
extra: {
|
|
36
|
+
apiUrl: "https://test-api.example.com",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
manifest: {
|
|
40
|
+
extra: {
|
|
41
|
+
apiUrl: "https://test-api.example.com",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
}));
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Expo SecureStore
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const mockSecureStore: Record<string, string> = {};
|
|
51
|
+
|
|
52
|
+
jest.mock("expo-secure-store", () => ({
|
|
53
|
+
setItemAsync: jest.fn((key: string, value: string) => {
|
|
54
|
+
mockSecureStore[key] = value;
|
|
55
|
+
return Promise.resolve();
|
|
56
|
+
}),
|
|
57
|
+
getItemAsync: jest.fn((key: string) => {
|
|
58
|
+
return Promise.resolve(mockSecureStore[key] ?? null);
|
|
59
|
+
}),
|
|
60
|
+
deleteItemAsync: jest.fn((key: string) => {
|
|
61
|
+
delete mockSecureStore[key];
|
|
62
|
+
return Promise.resolve();
|
|
63
|
+
}),
|
|
64
|
+
}));
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### React Native Reanimated
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
jest.mock("react-native-reanimated", () =>
|
|
71
|
+
require("react-native-reanimated/mock")
|
|
72
|
+
);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### React Native Gesture Handler
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
jest.mock("react-native-gesture-handler", () => ({
|
|
79
|
+
GestureHandlerRootView: ({ children }: { children: React.ReactNode }) =>
|
|
80
|
+
children,
|
|
81
|
+
Swipeable: "Swipeable",
|
|
82
|
+
DrawerLayout: "DrawerLayout",
|
|
83
|
+
State: {},
|
|
84
|
+
PanGestureHandler: "PanGestureHandler",
|
|
85
|
+
TapGestureHandler: "TapGestureHandler",
|
|
86
|
+
FlingGestureHandler: "FlingGestureHandler",
|
|
87
|
+
ForceTouchGestureHandler: "ForceTouchGestureHandler",
|
|
88
|
+
LongPressGestureHandler: "LongPressGestureHandler",
|
|
89
|
+
NativeViewGestureHandler: "NativeViewGestureHandler",
|
|
90
|
+
PinchGestureHandler: "PinchGestureHandler",
|
|
91
|
+
RotationGestureHandler: "RotationGestureHandler",
|
|
92
|
+
RawButton: "RawButton",
|
|
93
|
+
BaseButton: "BaseButton",
|
|
94
|
+
RectButton: "RectButton",
|
|
95
|
+
BorderlessButton: "BorderlessButton",
|
|
96
|
+
TouchableHighlight: "TouchableHighlight",
|
|
97
|
+
TouchableNativeFeedback: "TouchableNativeFeedback",
|
|
98
|
+
TouchableOpacity: "TouchableOpacity",
|
|
99
|
+
TouchableWithoutFeedback: "TouchableWithoutFeedback",
|
|
100
|
+
ScrollView: "ScrollView",
|
|
101
|
+
Directions: {},
|
|
102
|
+
}));
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Expo Router Navigation
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
const mockRouter = {
|
|
109
|
+
push: jest.fn(),
|
|
110
|
+
replace: jest.fn(),
|
|
111
|
+
back: jest.fn(),
|
|
112
|
+
canGoBack: jest.fn(() => true),
|
|
113
|
+
setParams: jest.fn(),
|
|
114
|
+
navigate: jest.fn(),
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const mockSegments: string[] = [];
|
|
118
|
+
const mockPathname = "/";
|
|
119
|
+
|
|
120
|
+
jest.mock("expo-router", () => ({
|
|
121
|
+
...jest.requireActual("expo-router"),
|
|
122
|
+
useRouter: () => mockRouter,
|
|
123
|
+
useSegments: () => mockSegments,
|
|
124
|
+
usePathname: () => mockPathname,
|
|
125
|
+
useLocalSearchParams: () => ({}),
|
|
126
|
+
useGlobalSearchParams: () => ({}),
|
|
127
|
+
Link: "Link",
|
|
128
|
+
Redirect: "Redirect",
|
|
129
|
+
}));
|
|
130
|
+
|
|
131
|
+
// Export for test access
|
|
132
|
+
export { mockRouter };
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### React Navigation (for non-Expo Router)
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
const mockNavigation = {
|
|
139
|
+
navigate: jest.fn(),
|
|
140
|
+
goBack: jest.fn(),
|
|
141
|
+
setOptions: jest.fn(),
|
|
142
|
+
addListener: jest.fn(() => () => {}),
|
|
143
|
+
removeListener: jest.fn(),
|
|
144
|
+
dispatch: jest.fn(),
|
|
145
|
+
reset: jest.fn(),
|
|
146
|
+
isFocused: jest.fn(() => true),
|
|
147
|
+
canGoBack: jest.fn(() => true),
|
|
148
|
+
getParent: jest.fn(() => null),
|
|
149
|
+
getState: jest.fn(() => ({ routes: [], index: 0 })),
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const mockRoute = {
|
|
153
|
+
params: {},
|
|
154
|
+
name: "TestScreen",
|
|
155
|
+
key: "test-key",
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
jest.mock("@react-navigation/native", () => ({
|
|
159
|
+
...jest.requireActual("@react-navigation/native"),
|
|
160
|
+
useNavigation: () => mockNavigation,
|
|
161
|
+
useRoute: () => mockRoute,
|
|
162
|
+
useFocusEffect: jest.fn(callback => callback()),
|
|
163
|
+
useIsFocused: jest.fn(() => true),
|
|
164
|
+
}));
|
|
165
|
+
|
|
166
|
+
export { mockNavigation, mockRoute };
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Module Mocks
|
|
170
|
+
|
|
171
|
+
### Mocking Default Exports
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
jest.mock("./analytics", () => ({
|
|
175
|
+
__esModule: true,
|
|
176
|
+
default: {
|
|
177
|
+
track: jest.fn(),
|
|
178
|
+
identify: jest.fn(),
|
|
179
|
+
},
|
|
180
|
+
}));
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Mocking Named Exports
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
jest.mock("./utils", () => ({
|
|
187
|
+
formatDate: jest.fn(date => "2024-01-01"),
|
|
188
|
+
calculateTotal: jest.fn(() => 100),
|
|
189
|
+
}));
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Partial Module Mocking
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
jest.mock("./api", () => ({
|
|
196
|
+
...jest.requireActual("./api"),
|
|
197
|
+
fetchUser: jest.fn(), // Only mock this function
|
|
198
|
+
}));
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Auto-Mocking with Manual Override
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
// Automatically mock all exports
|
|
205
|
+
jest.mock("./service");
|
|
206
|
+
|
|
207
|
+
// Then customize specific functions
|
|
208
|
+
import { myFunction } from "./service";
|
|
209
|
+
(myFunction as jest.Mock).mockReturnValue("custom value");
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Function Mocking
|
|
213
|
+
|
|
214
|
+
### Basic Mock Functions
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
const mockCallback = jest.fn();
|
|
218
|
+
|
|
219
|
+
// With return value
|
|
220
|
+
const mockGetName = jest.fn(() => "John");
|
|
221
|
+
|
|
222
|
+
// With implementation
|
|
223
|
+
const mockCalculate = jest.fn((a, b) => a + b);
|
|
224
|
+
|
|
225
|
+
// Chained return values
|
|
226
|
+
const mockFetch = jest
|
|
227
|
+
.fn()
|
|
228
|
+
.mockReturnValueOnce("first")
|
|
229
|
+
.mockReturnValueOnce("second")
|
|
230
|
+
.mockReturnValue("default");
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Async Mock Functions
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
// Resolved promise
|
|
237
|
+
const mockFetchData = jest.fn().mockResolvedValue({ id: 1, name: "John" });
|
|
238
|
+
|
|
239
|
+
// Rejected promise
|
|
240
|
+
const mockFetchError = jest.fn().mockRejectedValue(new Error("Network error"));
|
|
241
|
+
|
|
242
|
+
// Sequential async responses
|
|
243
|
+
const mockApi = jest
|
|
244
|
+
.fn()
|
|
245
|
+
.mockResolvedValueOnce({ status: "loading" })
|
|
246
|
+
.mockResolvedValueOnce({ status: "complete", data: [] });
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Asserting Mock Calls
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
// Was called
|
|
253
|
+
expect(mockFn).toHaveBeenCalled();
|
|
254
|
+
|
|
255
|
+
// Called specific number of times
|
|
256
|
+
expect(mockFn).toHaveBeenCalledTimes(3);
|
|
257
|
+
|
|
258
|
+
// Called with specific arguments
|
|
259
|
+
expect(mockFn).toHaveBeenCalledWith("arg1", "arg2");
|
|
260
|
+
|
|
261
|
+
// Last call arguments
|
|
262
|
+
expect(mockFn).toHaveBeenLastCalledWith("final");
|
|
263
|
+
|
|
264
|
+
// Nth call arguments
|
|
265
|
+
expect(mockFn).toHaveBeenNthCalledWith(1, "first");
|
|
266
|
+
expect(mockFn).toHaveBeenNthCalledWith(2, "second");
|
|
267
|
+
|
|
268
|
+
// Access all calls
|
|
269
|
+
expect(mockFn.mock.calls).toEqual([["first"], ["second"]]);
|
|
270
|
+
|
|
271
|
+
// Access results
|
|
272
|
+
expect(mockFn.mock.results[0].value).toBe("result");
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Clearing and Resetting Mocks
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
beforeEach(() => {
|
|
279
|
+
// Clear call history, keep implementation
|
|
280
|
+
mockFn.mockClear();
|
|
281
|
+
|
|
282
|
+
// Clear calls and reset implementation
|
|
283
|
+
mockFn.mockReset();
|
|
284
|
+
|
|
285
|
+
// Reset to original (unmocked) implementation
|
|
286
|
+
mockFn.mockRestore();
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// Clear all mocks at once
|
|
290
|
+
jest.clearAllMocks();
|
|
291
|
+
jest.resetAllMocks();
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## Timer Mocking
|
|
295
|
+
|
|
296
|
+
### Fake Timers
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
beforeEach(() => {
|
|
300
|
+
jest.useFakeTimers();
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
afterEach(() => {
|
|
304
|
+
jest.useRealTimers();
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test("debounced function", () => {
|
|
308
|
+
const callback = jest.fn();
|
|
309
|
+
debouncedFunction(callback);
|
|
310
|
+
|
|
311
|
+
expect(callback).not.toHaveBeenCalled();
|
|
312
|
+
|
|
313
|
+
jest.advanceTimersByTime(500);
|
|
314
|
+
|
|
315
|
+
expect(callback).toHaveBeenCalled();
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Date Mocking
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
beforeEach(() => {
|
|
323
|
+
jest.useFakeTimers();
|
|
324
|
+
jest.setSystemTime(new Date("2024-01-15T12:00:00Z"));
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
afterEach(() => {
|
|
328
|
+
jest.useRealTimers();
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("displays current date", () => {
|
|
332
|
+
render(<DateDisplay />);
|
|
333
|
+
expect(screen.getByText("January 15, 2024")).toBeOnTheScreen();
|
|
334
|
+
});
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## Apollo Client Mocking
|
|
338
|
+
|
|
339
|
+
### MockedProvider
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
import { MockedProvider } from "@apollo/client/testing";
|
|
343
|
+
|
|
344
|
+
const mocks = [
|
|
345
|
+
{
|
|
346
|
+
request: {
|
|
347
|
+
query: GET_USERS,
|
|
348
|
+
variables: { limit: 10 },
|
|
349
|
+
},
|
|
350
|
+
result: {
|
|
351
|
+
data: {
|
|
352
|
+
users: [
|
|
353
|
+
{ id: "1", name: "John" },
|
|
354
|
+
{ id: "2", name: "Jane" },
|
|
355
|
+
],
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
];
|
|
360
|
+
|
|
361
|
+
test("displays users", async () => {
|
|
362
|
+
render(
|
|
363
|
+
<MockedProvider mocks={mocks} addTypename={false}>
|
|
364
|
+
<UserList limit={10} />
|
|
365
|
+
</MockedProvider>
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
expect(await screen.findByText("John")).toBeOnTheScreen();
|
|
369
|
+
expect(screen.getByText("Jane")).toBeOnTheScreen();
|
|
370
|
+
});
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Error Mocks
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
const errorMocks = [
|
|
377
|
+
{
|
|
378
|
+
request: {
|
|
379
|
+
query: GET_USER,
|
|
380
|
+
variables: { id: "1" },
|
|
381
|
+
},
|
|
382
|
+
error: new Error("An error occurred"),
|
|
383
|
+
},
|
|
384
|
+
];
|
|
385
|
+
|
|
386
|
+
// Or GraphQL errors
|
|
387
|
+
const graphqlErrorMocks = [
|
|
388
|
+
{
|
|
389
|
+
request: {
|
|
390
|
+
query: GET_USER,
|
|
391
|
+
variables: { id: "1" },
|
|
392
|
+
},
|
|
393
|
+
result: {
|
|
394
|
+
errors: [{ message: "User not found" }],
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
];
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Mutation Mocks
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
const mutationMocks = [
|
|
404
|
+
{
|
|
405
|
+
request: {
|
|
406
|
+
query: CREATE_USER,
|
|
407
|
+
variables: { name: "John", email: "john@example.com" },
|
|
408
|
+
},
|
|
409
|
+
result: {
|
|
410
|
+
data: {
|
|
411
|
+
createUser: {
|
|
412
|
+
id: "1",
|
|
413
|
+
name: "John",
|
|
414
|
+
email: "john@example.com",
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
];
|
|
420
|
+
|
|
421
|
+
test("creates user on submit", async () => {
|
|
422
|
+
const user = userEvent.setup();
|
|
423
|
+
render(
|
|
424
|
+
<MockedProvider mocks={mutationMocks} addTypename={false}>
|
|
425
|
+
<UserForm />
|
|
426
|
+
</MockedProvider>
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
await user.type(screen.getByLabelText("Name"), "John");
|
|
430
|
+
await user.type(screen.getByLabelText("Email"), "john@example.com");
|
|
431
|
+
await user.press(screen.getByRole("button", { name: "Create" }));
|
|
432
|
+
|
|
433
|
+
expect(await screen.findByText("User created!")).toBeOnTheScreen();
|
|
434
|
+
});
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### Loading Delay
|
|
438
|
+
|
|
439
|
+
```typescript
|
|
440
|
+
const delayedMocks = [
|
|
441
|
+
{
|
|
442
|
+
request: {
|
|
443
|
+
query: GET_DATA,
|
|
444
|
+
},
|
|
445
|
+
result: {
|
|
446
|
+
data: { items: [] },
|
|
447
|
+
},
|
|
448
|
+
delay: 500, // Simulates network delay
|
|
449
|
+
},
|
|
450
|
+
];
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
## Context and Provider Mocking
|
|
454
|
+
|
|
455
|
+
### GluestackUIProvider Mock
|
|
456
|
+
|
|
457
|
+
GluestackUIProvider depends on NativeWind CSS variables that are not available in the test environment. Mock the entire module in integration tests:
|
|
458
|
+
|
|
459
|
+
```typescript
|
|
460
|
+
jest.mock("@/components/ui/gluestack-ui-provider", () => ({
|
|
461
|
+
GluestackUIProvider: ({ children }: { children: React.ReactNode }) => (
|
|
462
|
+
<>{children}</>
|
|
463
|
+
),
|
|
464
|
+
}));
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
Place this in integration test files or shared test utilities rather than global `jest.setup.js`, as it's only needed when testing components that use the provider.
|
|
468
|
+
|
|
469
|
+
### Custom Render with Providers
|
|
470
|
+
|
|
471
|
+
```typescript
|
|
472
|
+
import { render, RenderOptions } from "@testing-library/react-native";
|
|
473
|
+
|
|
474
|
+
interface WrapperProps {
|
|
475
|
+
children: React.ReactNode;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const AllProviders = ({ children }: WrapperProps) => (
|
|
479
|
+
<ThemeProvider theme={testTheme}>
|
|
480
|
+
<AuthProvider value={mockAuthContext}>
|
|
481
|
+
<MockedProvider mocks={defaultMocks}>
|
|
482
|
+
{children}
|
|
483
|
+
</MockedProvider>
|
|
484
|
+
</AuthProvider>
|
|
485
|
+
</ThemeProvider>
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
const customRender = (
|
|
489
|
+
ui: React.ReactElement,
|
|
490
|
+
options?: Omit<RenderOptions, "wrapper">
|
|
491
|
+
) => render(ui, { wrapper: AllProviders, ...options });
|
|
492
|
+
|
|
493
|
+
export * from "@testing-library/react-native";
|
|
494
|
+
export { customRender as render };
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
### Mocking Context Values
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
const mockAuthContext = {
|
|
501
|
+
user: { id: "1", name: "Test User" },
|
|
502
|
+
isAuthenticated: true,
|
|
503
|
+
login: jest.fn(),
|
|
504
|
+
logout: jest.fn(),
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
test("displays user name", () => {
|
|
508
|
+
render(
|
|
509
|
+
<AuthContext.Provider value={mockAuthContext}>
|
|
510
|
+
<UserProfile />
|
|
511
|
+
</AuthContext.Provider>
|
|
512
|
+
);
|
|
513
|
+
|
|
514
|
+
expect(screen.getByText("Test User")).toBeOnTheScreen();
|
|
515
|
+
});
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
## Image and Asset Mocking
|
|
519
|
+
|
|
520
|
+
```typescript
|
|
521
|
+
jest.mock("@/assets/logo.png", () => "mocked-logo");
|
|
522
|
+
|
|
523
|
+
jest.mock(
|
|
524
|
+
"*.png",
|
|
525
|
+
() => ({
|
|
526
|
+
__esModule: true,
|
|
527
|
+
default: "mocked-image",
|
|
528
|
+
}),
|
|
529
|
+
{ virtual: true }
|
|
530
|
+
);
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
## Fetch and API Mocking
|
|
534
|
+
|
|
535
|
+
### Global Fetch Mock
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
global.fetch = jest.fn(() =>
|
|
539
|
+
Promise.resolve({
|
|
540
|
+
ok: true,
|
|
541
|
+
json: () => Promise.resolve({ data: "test" }),
|
|
542
|
+
status: 200,
|
|
543
|
+
headers: new Headers(),
|
|
544
|
+
})
|
|
545
|
+
) as jest.Mock;
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### MSW (Mock Service Worker) Alternative
|
|
549
|
+
|
|
550
|
+
For complex API mocking, consider using MSW:
|
|
551
|
+
|
|
552
|
+
```typescript
|
|
553
|
+
import { setupServer } from "msw/node";
|
|
554
|
+
import { http, HttpResponse } from "msw";
|
|
555
|
+
|
|
556
|
+
const server = setupServer(
|
|
557
|
+
http.get("/api/users", () => {
|
|
558
|
+
return HttpResponse.json([
|
|
559
|
+
{ id: 1, name: "John" },
|
|
560
|
+
{ id: 2, name: "Jane" },
|
|
561
|
+
]);
|
|
562
|
+
})
|
|
563
|
+
);
|
|
564
|
+
|
|
565
|
+
beforeAll(() => server.listen());
|
|
566
|
+
afterEach(() => server.resetHandlers());
|
|
567
|
+
afterAll(() => server.close());
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
## Console Mocking
|
|
571
|
+
|
|
572
|
+
Suppress expected console warnings/errors:
|
|
573
|
+
|
|
574
|
+
```typescript
|
|
575
|
+
const originalError = console.error;
|
|
576
|
+
|
|
577
|
+
beforeAll(() => {
|
|
578
|
+
console.error = jest.fn((...args) => {
|
|
579
|
+
// Suppress specific warnings
|
|
580
|
+
if (args[0]?.includes("Warning: Expected warning")) {
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
originalError.apply(console, args);
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
afterAll(() => {
|
|
588
|
+
console.error = originalError;
|
|
589
|
+
});
|
|
590
|
+
```
|