If you use mock-fs package the line numbers are shown icorrectly.
import Dog from "./Dog";
import * as mock from "mock-fs";
describe("Dog", () => {
beforeAll(() => {
mock({
"path/to/file.txt": "my text content",
});
});
afterAll(() => {
mock.restore();
})
test("should woof", () => {
const dog = new Dog();
expect(dog.woof()).toBe("Woof!____ SHOULD FAIL AND DISPLAY LINE NUMBER 19");
// but it shows error at line number 16
});
});
When running the tests, the line number should be shown correctly. But instead the JS line number is shown (not the TS input file line number)
https://github.com/jhm-ciberman/ts-jest-bug
I cannot configure it because the test NEEDs to fail to show the line number.
@jhm-ciberman allowSyntheticDefaultImports needed to be set to true when using default imports. I've sent a PR with the patch to the linked repo. Let me know if that works for you
Wow! I have merged it and It works perfect. Can you please explain me why does it works? (Or why the error was produced in first place). Or what does the allowSyntheticDefaultImports flag do?
Thanks in advance!
I tryed in my full original project where I had this problem and I couldn't get to work. The repo is listed in: https://github.com/kulshekhar/ts-jest/issues/404
Can you help me figuring what is wrong?
@jhm-ciberman I'm not sure I can be as technically accurate as I'd want to be when describing allowSyntheticDefaultImports so I'll just refer you to the documentation (which is admittedly very sparse) : https://www.typescriptlang.org/docs/handbook/compiler-options.html
Can you help me figuring what is wrong?
If you can create a minimal repo, I'll be happy to take a look at it after work. Without this, it usually takes too much time and in most cases, nothing gets fixed.
AllowSyntheticdefaultimports is just a check for the ts compiler that tells it something is creating synthetic default imports. We pick this up and run the code through babel to actually create the synthetic default imports.
@kulshekhar there is a repo setup for this error
git clone https://github.com/jhm-ciberman/docs_gm.git
cd docs_gm
git checkout 5e2920b
npm install
npm test
Could you take a look at it?
@thiagoh is it the same issue your facing?
In either case, it would be better to open a new issue (link to this if it helps) so that your specific case can be discussed/fixed there
@kulshekhar, I'm facing the same issue, yeah. But the repo I'm having these problems are private, unfortunately. Can you take a look at @jhm-ciberman 's repo?
@thiagoh I'd like to look into this but without a minimal repo, I'm hesitant because there have been several instances where looking at a larger project has resulted in false leads and wasted time.
If you can replicate this issue with just a couple of files in src and test folders, I'll be happy to take a look at it after/before work. Without that, I'll have to wait till I can set aside a longer window of time.
And if this is opened as a new issue, there's less chance of it being overlooked by mistake
Most helpful comment
@jhm-ciberman
allowSyntheticDefaultImportsneeded to be set totruewhen using default imports. I've sent a PR with the patch to the linked repo. Let me know if that works for you