0

I've encountered a persistent issue in my project that has been causing a significant delay. The problem revolves around a simple test scenario, but despite my efforts, I haven't been able to identify the root cause. This has hindered my progress and prevented me from proceeding with the project.

NOTE

@IsValidMobileNumber()

is a custom decorator exported in src/_core/decorator/index.ts

ERROR

> jest ./auth.controller.spec.ts

 FAIL  src/auth/auth.controller.spec.ts
  ● Test suite failed to run

    TypeError: (0 , decorator_1.IsValidMobileNumber) is not a function

      28 |   @IsNotEmpty()
      29 |   @IsString()
    > 30 |   @IsValidMobileNumber()
         |                       ^
      31 |   mobileNumber: string;
      32 | }
      33 |

      at Object.<anonymous> (src/user/dto/client-validate.param.dto.ts:30:23)
      at Object.<anonymous> (src/user/controller/client.controller.ts:95:1)
      at Object.<anonymous> (src/user/user.module.ts:4:1)
      at Object.<anonymous> (src/user/index.ts:2:1)
      at Object.<anonymous> (src/_core/decorator/is-email-unique.decorator.ts:10:1)
      at Object.<anonymous> (src/_core/decorator/index.ts:11:1)
      at Object.<anonymous> (src/auth/auth.controller.ts:3:1)
      at Object.<anonymous> (src/auth/auth.controller.spec.ts:2:1)

package.json

 "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "roots": [
      "src"
    ],
    "moduleNameMapper": {
      "^@core/(.*)$": "<rootDir>/src/_core/$1",
      "^@module/activity/(.*)$": "<rootDir>/src/activity/$1",
      "^@module/auth$": "<rootDir>/src/auth/index",
      "^@module/role/(.*)$": "<rootDir>/src/role/$1",
      "^@module/user/(.*)$": "<rootDir>/src/user/$1",
      "^@module/health/(.*)$": "<rootDir>/src/health/$1",
      "^@module/notification/(.*)$": "<rootDir>/src/notification/$1",
      "^@module/report/(.*)$": "<rootDir>/src/report/$1",
      "^@module/file/(.*)$": "<rootDir>/src/file/$1",
    },
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "paths": {

      "@core/config": [
        "src/_core/config/index"
      ],
      "@core/database": [
        "src/_core/database/index"
      ],
      "@core/email": [
        "src/_core/email/index"
      ],
      "@core/enum": [
        "src/_core/enum/index"
      ],
      "@core/guard": [
        "src/_core/guard/index"
      ],
      "@core/interceptor": [
        "src/_core/interceptor/index"
      ],
      "@core/interface": [
        "src/_core/interface/index"
      ],
      "@core/middleware": [
        "src/_core/middleware/index"
      ],
      "@core/notification": [
        "src/_core/notification/index"
      ],
      "@core/strategy": [
        "src/_core/strategy/index"
      ],
      "@core/utils": [
        "src/_core/utils/index"
      ],
      "@core/logger": [
        "src/_core/logger/index"
      ],
      "@core/service": [
        "src/_core/service/index"
      ],
      "@core/decorator": [
        "src/_core/decorator/index"
      ],
      "@core/event": [
        "src/_core/event/index"
      ],
      "@core/swagger": [
        "src/_core/swagger/index"
      ],
      "@core/error": [
        "src/_core/error/index"
      ],
      // others
      "@module/activity/*": [
        "src/activity/*"
      ],
      "@module/auth": [
        "src/auth/index"
      ],
      "@module/role/*": [
        "src/role/*"
      ],
      "@module/user/*": [
        "src/user/*"
      ],
      "@module/health/*": [
        "src/health/*"
      ],
      "@module/notification/*": [
        "src/notification/*"
      ],
      "@module/report/*": [
        "src/report/*"
      ],
      "@module/address/*": [
        "src/address/*"
      ],
      "@module/file/*": [
        "src/file/*"
      ],
      "@module/whitelist/*": [
        "src/whitelist/*"
      ],
    }
  }
}

and this is the folder structure the _core folder consists decorator, dto, and more.

enter image description here?

I would greatly appreciate any insights or guidance to help me resolve this issue. and I'll be glad to edit this if there are any confusions. Thank you for your assistance.

Koala
  • 352
  • 2
  • 7
  • 18
  • I think @IsPhoneNumber() is the available decorator from 'class-validator', may be the issue caused due to this. let know if it still presists. thanks – y051 Jun 30 '23 at 05:54
  • hi @y051 the @IsValidMobileNumber() is a custom decorator exported in _core/decorator/index – Koala Jun 30 '23 at 07:24

0 Answers0