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

type script reference path is not getting resolved in jest #9805

Closed
pallabrath opened this issue Apr 13, 2020 · 4 comments
Closed

type script reference path is not getting resolved in jest #9805

pallabrath opened this issue Apr 13, 2020 · 4 comments

Comments

@pallabrath
Copy link

In one of the ts file (query_ctrl.ts) the module import are like below

///

import { QueryCtrl } from 'app/plugins/sdk';
export class MyQueryCtrl extends QueryCtrl
{ .....

In module.ts
export {
MyQueryCtrl as QueryCtrl
};
While in jest test module.test.ts
import { QueryCtrl } from '../../datasource/module'

● Test suite failed to run

Cannot find module 'app/plugins/sdk' from 'query_ctrl.ts'

Require stack:
  src/datasource/query_ctrl.ts
  src/datasource/module.ts
  src/specs/datasource/module.test.ts


   6 | import { Utils } from './Utils';
>  7 | import { QueryCtrl } from 'app/plugins/sdk';
     | ^
  
   9 | 
  10 | 

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:296:11)
  at Object.<anonymous> (src/datasource/query_ctrl.ts:7:1)
@pallabrath
Copy link
Author

jest.config.js

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
coverageDirectory: "work/coverage",
};

@SimenB
Copy link
Member

SimenB commented Apr 13, 2020

Yeah, Jest doesn't support that, and we won't - starting to deal with how bundlers and type checkers do resolution is out of scope for us. You need to use moduleNameMapper. This might be something ts-jest could do automatically, though? Not sure - might be worth an issue over there.

@SimenB SimenB closed this as completed Apr 13, 2020
@pallabrath
Copy link
Author

Thanks, I had tried moduleNameMapper, not much luck. Any way will try with ts-js. Lets see

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants