Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update jest to solve typescript path mapping mock bug #2097

Closed
dianjuar opened this issue Apr 27, 2019 · 2 comments
Closed

Update jest to solve typescript path mapping mock bug #2097

dianjuar opened this issue Apr 27, 2019 · 2 comments

Comments

@dianjuar
Copy link

dianjuar commented Apr 27, 2019

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I'm using Typescript Path Mapping and jest have an issue related with that. This issue causes that jest.mock doesn't import an auto-mock, imports the real one

This issue already solved by a merged pull-request.

I couldn't find in what version of jest that problem was solved, but I think the jest version installed by the nest cli the problem remains 😟.

Expected behavior

Have a jest version with full support of typescript path mapping

Minimal reproduction of the problem with instructions

The same exposed on the jest issue

Set up, a typescript path map and use it in a jest.mock and see that there is no automock set, the original is imported.

Basically this doesn't do the work

import { NpmStatsService } from '@shared/npm-stats/npm-stats.service';
jest.mock('@shared/npm-stats/npm-stats.service'); // ----> With this the NpmStatsService should be auto-mocked but doesn't :/

What is the motivation / use case for changing the behavior?

Typescript paths maps allows you to have a more maintainable code and if you have unit test, you can not use it 😞

Environment

Nest version: 6.1.1 -> The latest

 
For Tooling issues:
- Node version: 10.15  
- Platform:  Linux

Others:
jest: ^23.6.0  -> latest install by nest-cli
ts-jest: ^23.10.5  -> latest install by nest-cli


I install the last one of jest": "^24.7.1 and ts-jest: ^24.0.2 and the problem is not there 😄.

Maybe this problem is solve by update jest and ts-jest to the latest versions

This is my package.json with the problem solved file just for the record:

"dependencies": {
    "@nestjs/common": "^6.1.1",
    "@nestjs/core": "^6.1.1",
    "@nestjs/platform-express": "^6.1.1",
    "api-npm": "^1.0.0",
    "class-transformer": "^0.2.0",
    "nedb": "^1.8.0",
    "nedb-promises": "^3.0.2",
    "node-telegram-bot-api": "^0.30.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^2.6.2",
    "rxjs": "^6.2.2"
  },
  "devDependencies": {
    "@commitlint/cli": "^7.5.2",
    "@commitlint/config-conventional": "^7.5.0",
    "@nestjs/cli": "^6.3.0",
    "@nestjs/testing": "^6.1.1",
    "@types/express": "^4.16.0",
    "@types/jest": "^24.0.11",
    "@types/nedb": "^1.8.7",
    "@types/node": "^10.7.1",
    "@types/node-telegram-bot-api": "^0.30.4",
    "@types/supertest": "^2.0.5",
    "cross-env": "^5.2.0",
    "husky": "^2.1.0",
    "jest": "^24.7.1",
    "jest-sonar-reporter": "^2.0.0",
    "nodemon": "^1.18.3",
    "prettier": "^1.14.2",
    "sonar-scanner": "^3.1.0",
    "supertest": "^3.4.1",
    "ts-jest": "^24.0.2",
    "ts-loader": "^4.4.2",
    "ts-node": "^7.0.1",
    "tsconfig-paths": "^3.7.0",
    "tslint": "5.12.1",
    "typescript": "^3.2.4"
  }
@dianjuar dianjuar changed the title Update jest to solve typescript path mapping mock Update jest to solve typescript path mapping mock bug Apr 27, 2019
@kamilmysliwiec
Copy link
Member

Hi @dianjuar,
I believe that this issue should be rather reported in both @nestjs/schematics and typescript-starter repo :)

@lock
Copy link

lock bot commented Sep 23, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants