Przeglądaj źródła

♻️ refactor(test): optimize test configuration and payment test setup

- add '~/' path alias for tests directory in jest.config.js and tsconfig.json
- simplify Taro.requestPayment mock import in payment.test.ts using '~/' alias
- remove redundant local mock implementation for Taro.requestPayment in payment test file
yourname 3 miesięcy temu
rodzic
commit
513b4a8ab6
3 zmienionych plików z 4 dodań i 7 usunięć
  1. 1 0
      mini/jest.config.js
  2. 2 7
      mini/tests/unit/payment.test.ts
  3. 1 0
      mini/tsconfig.json

+ 1 - 0
mini/jest.config.js

@@ -4,6 +4,7 @@ module.exports = {
   setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],
   moduleNameMapper: {
     '^@/(.*)$': '<rootDir>/src/$1',
+    '^~/(.*)$': '<rootDir>/tests/$1',
     '^@tarojs/taro$': '<rootDir>/tests/__mocks__/taroMock.ts',
     '\.(css|less|scss|sass)$': '<rootDir>/tests/__mocks__/styleMock.js',
     '\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':

+ 2 - 7
mini/tests/unit/payment.test.ts

@@ -16,13 +16,8 @@ import {
   verifyPaymentParamsIntegrity
 } from '@/utils/payment'
 
-// Mock Taro.requestPayment
-const mockRequestPayment = jest.fn()
-jest.mock('@tarojs/taro', () => ({
-  default: {
-    requestPayment: mockRequestPayment
-  }
-}))
+
+import { mockRequestPayment } from '~/__mocks__/taroMock'
 
 describe('Payment Utils', () => {
   beforeEach(() => {

+ 1 - 0
mini/tsconfig.json

@@ -22,6 +22,7 @@
     ],
     "paths": {
       "@/*": ["./src/*"],
+      "~/*": ["./tests/*"],
       "@d8d/server/*": ["../packages/server/src/*"]
     }
   },