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

Allow ignoring consoles on a case by case basis #36

Open
mackenco opened this issue Mar 6, 2019 · 4 comments
Open

Allow ignoring consoles on a case by case basis #36

mackenco opened this issue Mar 6, 2019 · 4 comments
Labels
status: accepting prs Please, send a pull request to resolve this! 🙏 type: feature New enhancement or request 🚀

Comments

@mackenco
Copy link

mackenco commented Mar 6, 2019

There can be cases where we're console.erroring on purpose (e.g. my component tries to fetch some data -> if that fails, I'd like to log it). These will still warn in our tests though. Would be nice to have some ignore syntax, perhaps like eslint:

// console-fail-ignore-next-line
console.error('I know what I'm doing')
@JoshuaKGoldberg
Copy link
Owner

Ah, console-fail-ignore would be quite difficult, as this might not have access to source files: for example, when running in a Mocha browser test.

How about a part of the cft API?

require("console-fail-test").cft({
    console: {
        warn: {
            allow: [/I know what I'm doing/],
        },
    },
});

@JoshuaKGoldberg
Copy link
Owner

@all-contributors please add @mackenco for ideas.

🤖 Beep boop! This comment was added automatically by all-contributors-auto-action.
Not all contributions can be detected from Git & GitHub alone. Please comment any missing contribution types this bot missed.
...and of course, thank you for contributing! 💙

Copy link
Contributor

@JoshuaKGoldberg

I've put up a pull request to add @mackenco! 🎉

I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use valid contribution names.

JoshuaKGoldberg pushed a commit that referenced this issue Jan 17, 2024
Adds @mackenco as a contributor for ideas.

This was requested by JoshuaKGoldberg [in this
comment](#36 (comment))

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
@vorant94
Copy link

vorant94 commented Dec 18, 2024

in my case manually mocking the implementation helps to both check that console.error was called, but also it passes tests with plugin on

it("should return error if no known errors were passed", () => {
	const error = new CustomError();
	const callback = () => {
		throw error;
	};

	const consoleSpy = vi
		.spyOn(console, "error")
		.mockImplementationOnce(() => {});

	expect(catchError(callback)).toEqual([error]);
	expect(consoleSpy, "should log error to console").toBeCalledWith(error);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! 🙏 type: feature New enhancement or request 🚀
Projects
None yet
Development

No branches or pull requests

3 participants