-
Notifications
You must be signed in to change notification settings - Fork 18
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
undefined returned when using typescript with jest #9
Comments
Hi @abhishek-raj. Could you create a repository which I can clone, install, and repro? Thanks |
https://github.com/infctr/ts-jest-object-proxy About repro: Jest Adding this line results in missing classnames in the snapshot It does work with css modules files tho |
This is repro: https://github.com/abhishek-raj/identity-obj-proxy-issue9 The HelloWorld.test.tsx from src/webparts/helloWorld/tests/HelloWorld.test.tsx has a import of styles object which should be replaced with obj-identity-proxy but for some reason it does not as you can see from the tests. |
Hi all! I have the same issue. Do you need my repo to check? |
@abhishek-raj Did you try to enable
|
@abhishek-raj It looks like you're testing against SPFx. I had the same issue as well and attempted @andribo solution, which made identity-obj-proxy work as expected, however, that caused the project to not build as I ended up having to mock my scss, here's the mock that I used inside my test file. jest.mock('FileName.module.scss',()=>{
return {default:{
shimmer:'shimmer',
container:'container',
row:'row',
column:'column',
title:'title',
subTitle:'subTitle',
description:'description',
button:'button',
label:'label'
}};
}); So it looks like we're stuck with manual mocks inside SPFx testing until they upgrade the typescript version inside gulp build. Hope this helps. |
@bthurlow Yes I am testing against the spfx. Guess we have to wait till they upgrade the typescript version. |
@andribo I'm confused... you suggest trying In other words, in a new project:
jest config:
tsconfig.json:
test.spec.ts:
|
So it appears that with
I don't know nearly enough about the inner workings of this library to understand this behavior or if there's anything that can be done about it, but it's certainly an undesirable pitfall. |
@aaronbeall there is a workaround for importing with |
Marking it closed as this is working with latest SPFx 1.8.0 and TypeScript 3.3(This is the version I tested - should work with any typescript version after 2.7 which supports esModuleInterop). Need to use |
- added `exModuleInterop` to tsconfig.json - references keyz/identity-obj-proxy#9 (comment) - fixes #8
- added `exModuleInterop` to tsconfig.json - references keyz/identity-obj-proxy#9 (comment)
Hi everyone. I am dependeing on Typescript 2.4.2. The Configuration with moduleNameMapper here does not work. My scss varaibles are all undefined within a testrun. Is it possible, that the expression under moduleNameMapper simply does not hit filese like: my.module.scss ? |
I am using jest with typescript in my projects. I am getting undefined for all my .ts files using identity-obj-proxy but .js files work as expected.
This is my tsconfig.json:
This is my jest configuration:
My test file(.ts):
If I save the file as .js then everything seems to work but not in .ts or .tsx files.
The text was updated successfully, but these errors were encountered: