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

We should only override console methods before each test #5

Merged
merged 2 commits into from
Oct 8, 2021

Conversation

NikhilVerma
Copy link
Contributor

@NikhilVerma NikhilVerma commented Sep 30, 2021

This fixes the issue where this utility will swallow any console error methods logged outside the test environments. e.g. errors logged BEFORE setup/teardown of Jest tests.

I am also using the more native jest.spyOn to spy on the tests.

This fixes the issue where this utility will swallow any console error methods logged outside the test environments. e.g. errors logged BEFORE setup/teardown of Jest tests.
@ValentinH
Copy link
Owner

Could you please explain a bit more about "swallow any console error methods logged outside the test environments" please? Do you have an example of such an issue?

@NikhilVerma
Copy link
Contributor Author

NikhilVerma commented Oct 8, 2021

@ValentinH absolutely! here is a rough example

// Any errors thrown here will never be shown to the user
throwConsoleError();

describe("my-test", () => {
	it("fails on console", () => {
		expect.assertions(1);
		// This will work fine
		throwConsoleError();
		expect(1).toStrictEqual(1);
	});
});

function throwConsoleError() {
	console.error("I am a console error");
}

@ValentinH
Copy link
Owner

I just tested it and it works great! Thanks for the fix 🙏

@ValentinH ValentinH merged commit a4a5159 into ValentinH:main Oct 8, 2021
@ValentinH
Copy link
Owner

Published as 2.0.5 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants