question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line numbers are shown incorrectly when ussing mock-fs package.

See original GitHub issue
  • Issue

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
	});
});
  • Expected behavior

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)

  • Link to a minimal repo that reproduces this issue

https://github.com/jhm-ciberman/ts-jest-bug

  • Optional (but highly recommended) - Configure Travis (or your favorite system) with the minimal repo

I cannot configure it because the test NEEDs to fail to show the line number.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
kulshekharcommented, Jan 1, 2018

@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

1reaction
kulshekharcommented, Feb 7, 2018

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to Mock Node fs Modules with Sinon
js . I think the problem arises due to how the mocked method is nested within the imported module fs as fs.promises.readdir ....
Read more >
How to Mock the File System for Unit Testing in .NET
In this article, we are going to learn how to mock the file system and unit test a component that interacts with the...
Read more >
mock-fs
This lets you run tests against a set of mock files and directories instead of lugging around a bunch of test fixtures.
Read more >
How to mock files with TestDouble, TypeScript and Jest
In our case, we will be giving advice based on a fetched number of friends for a given person. import { fetchNumberOfFriendsFor }...
Read more >
Best Practices for Spies, Stubs and Mocks in Sinon.js
In this test, we're using once and withArgs to define a mock which checks both the number of calls and the arguments given....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found