nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.04k stars 7.56k forks source link

Jest test is failing on nestjs exception #11139

Closed lastdoctor closed 1 year ago

lastdoctor commented 1 year ago

Is there an existing issue for this?

Current behavior

The Jest unit test is failing to throw new instance NotFoundException

ts config

{
  "compilerOptions": {
    "lib": [
      "es5",
      "es6"
    ],
    "target": "es6",
    "removeComments": true,
    "outDir": "dist",
    "sourceMap": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "types": ["node", "jest"],
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "resolveJsonModule": true
  },
  "exclude": ["src//*.spec.ts", "src//*.orm-entity.ts"],
  "paths": {
    "elastic-apm-node": [
      "./node_modules/elastic-apm-nest/types/elastic-apm-node/index.d.ts"
    ]
  }
}

jest config

const config: Config.InitialOptions = {
  moduleFileExtensions: ['ts', 'js'],
  rootDir: '.',
  roots: ['src', 'test'],
  testEnvironment: 'node',
  maxWorkers: configUnitTests.jestWorkers,
  testRegex: '.unit.test.ts$',
  transform: {
    '^.+\\.(t|j)s$': 'ts-jest',
  },
};
export default config;

Minimum reproduction code

https://stackblitz.com/edit/nestjs-typescript-starter-qnajwl?file=test/exampe.unit.test.ts

Steps to reproduce

1) jest --config jest.unit.ts 2) I see error

telegram-cloud-photo-size-2-5449444932138943745-y

Expected behavior

just past the test expectations expect(result).toBeInstanceOf(HttpException);

Package

Other package

No response

NestJS version

9.0.8

Packages versions

dependencies
{
"@babel/cli": "^7.12.10",
    "@babel/core": "^7.12.10",
    "@babel/plugin-proposal-class-properties": "^7.5.5",
    "@babel/plugin-proposal-optional-chaining": "^7.8.3",
    "@babel/plugin-transform-runtime": "^7.6.2",
    "@babel/preset-env": "^7.6.3",
    "@babel/runtime": "^7.14.8",
    "@nestjs/common": "^9.0.8",
    "@nestjs/config": "^1.1.5",
    "@nestjs/core": "^9.0.8",
    "@nestjs/jwt": "^8.0.0",
    "@nestjs/microservices": "^9.0.8",
    "@nestjs/mongoose": "9.0.2",
    "@nestjs/passport": "^7.1.5",
    "@nestjs/platform-express": "^9.0.8",
    "@nestjs/schedule": "^1.0.1",
    "@nestjs/swagger": "^6.0.5",
    "@nestjs/testing": "^8.4.4",
    "@nestjs/typeorm": "^8.0.3",
    "adm-zip": "^0.5.9",
    "amplitude": "^5.1.1",
    "amqp-connection-manager": "^3.2.2",
    "amqplib": "^0.8.0",
    "apple-signin-auth": "^1.4.1",
    "async-redis": "^1.1.7",
    "axios": "^0.21.0",
    "babel-plugin-module-resolver": "^4.0.0",
    "bcrypt": "^5.0.1",
    "bcryptjs": "^2.4.3",
    "bignumber.js": "^9.0.1",
    "body-parser": "^1.18.3",
    "cache-manager": "^4.1.0",
    "cache-manager-redis-store": "^2.0.0",
    "class-transformer": "0.4.0",
    "class-validator": "^0.13.1",
    "colors": "^1.4.0",
    "cookie-parser": "^1.4.5",
    "cross-env": "^7.0.2",
    "crypto-js": "^4.1.1",
    "csv-stringify": "^5.6.2",
    "dayjs": "^1.8.17",
    "dotenv-cli": "^4.0.0",
    "elastic-apm-nest": "^0.0.7",
    "elastic-apm-node": "^3.37.0",
    "express": "^4.17.1",
    "express-async-errors": "^3.1.1",
    "express-http-proxy": "^1.6.2",
    "express-mongo-sanitize": "^2.0.0",
    "express-session": "^1.17.1",
    "express-validator": "^6.4.0",
    "faker": "^5.5.3",
    "firebase": "^9.1.3",
    "firebase-admin": "^10.0.0",
    "fs": "^0.0.1-security",
    "geoip-lite": "^1.4.2",
    "googleapis": "^91.0.0",
    "helmet": "^4.4.1",
    "http-status-codes": "^2.1.4",
    "ioredis": "^4.19.2",
    "jest": "^26.6.3",
    "jsdom": "^15.0.0",
    "json-2-csv": "^3.14.4",
    "json2csv": "^4.5.2",
    "json2xml": "^0.1.3",
    "jsonwebtoken": "^8.5.1",
    "kleur": "^4.1.5",
    "lodash": "^4.17.21",
    "login-with-twitter": "^1.2.3",
    "mobile-detect": "^1.4.5",
    "moment": "^2.29.1",
    "mongoose": "6.2.2",
    "multer": "^1.4.2",
    "nanoid": "^3.1.23",
    "nestjs-pino": "^3.1.1",
    "node-cron": "^2.0.3",
    "node-csv": "^0.1.2",
    "node-fetch": "^2.6.1",
    "node-gcm": "^1.0.4",
    "nodemon": "^2.0.6",
    "npm-run-all": "^4.1.5",
    "numeral": "^2.0.6",
    "oauth-1.0a": "^2.2.6",
    "passport": "^0.4.1",
    "passport-cookie": "^1.0.9",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "pg": "^8.5.1",
    "pino-http": "^8.2.1",
    "pino-pretty": "^9.1.1",
    "prom-client": "^14.0.1",
    "pug": "^3.0.2",
    "query-string": "^6.9.0",
    "randomstring": "^1.2.1",
    "redis": "^4.2.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "7",
    "sha256": "^0.2.0",
    "short-id": "^0.1.0-1",
    "short-uuid": "^4.1.0",
    "socket.io-client": "^2.3.0",
    "sparkpost": "^2.1.4",
    "superagent": "^6.1.0",
    "supertest": "^6.2.2",
    "swagger-stats": "^0.99.2",
    "swagger-ui-express": "4.1.3",
    "ts-node": "^9.0.0",
    "tsconfig-paths": "^3.9.0",
    "twit": "^2.2.11",
    "typeorm": "0.2.31",
    "typescript": "^4.1.2",
    "ua-parser-js": "^1.0.32",
    "url-join": "^4.0.1",
    "uuid": "^3.3.2",
    "uuid-validate": "0.0.3",
    "uuidv4": "^6.2.12"
}
dev dependencies
{
"@golevelup/ts-jest": "^0.3.4",
    "@sinonjs/fake-timers": "^10.0.2",
    "@types/cache-manager": "^3.4.3",
    "@types/cookie-parser": "^1.4.2",
    "@types/express-session": "^1.17.3",
    "@types/jest": "^26.0.15",
    "@types/mongoose": "^5.4.6",
    "@types/node": "^14.14.10",
    "@types/sinonjs__fake-timers": "^8.1.2",
    "@typescript-eslint/eslint-plugin": "^4.9.0",
    "@typescript-eslint/parser": "^4.9.0",
    "dotenv": "^8.2.0",
    "eslint": "^7.14.0",
    "eslint-config-prettier": "^6.15.0",
    "eslint-plugin-prettier": "^3.1.4",
    "fishery": "^2.2.2",
    "lint-staged": "^10.5.3",
    "nodemon": "^2.0.6",
    "prettier": "^2.2.1",
    "prettier-config-airbnb": "^1.0.0",
    "ts-jest": "^26.4.4",
    "ts-mockito": "^2.6.1"
}

Node.js version

18.14.0

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 1 year ago

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.