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

🚀 Feature: Better support for test assertions #210

Open
3 tasks done
JoshuaKGoldberg opened this issue Sep 5, 2023 · 0 comments
Open
3 tasks done

🚀 Feature: Better support for test assertions #210

JoshuaKGoldberg opened this issue Sep 5, 2023 · 0 comments
Assignees
Labels
status: needs investigation Further research required...? 🔎 type: feature New enhancement or request 🚀

Comments

@JoshuaKGoldberg
Copy link
Owner

JoshuaKGoldberg commented Sep 5, 2023

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Overview

I've found myself writing code like 1-4 of the following spy instances:

let mockConsoleError: SpyInstance;
let mockConsoleInfo: SpyInstance;
let mockConsoleLog: SpyInstance;
let mockConsoleWarn: SpyInstance;

describe("...", () => {
	beforeEach(() => {
		mockConsoleError = vi
			.spyOn(console, "error")
			.mockImplementation(() => undefined);
		mockConsoleInfo = vi
			.spyOn(console, "info")
			.mockImplementation(() => undefined);
		mockConsoleLog = vi
			.spyOn(console, "log")
			.mockImplementation(() => undefined);
		mockConsoleWarn = vi
			.spyOn(console, "warn")
			.mockImplementation(() => undefined);
	});

	// ...
});

Surely there's got to be a more clean way of doing this?

I don't it's 100% doable right now, but I'd love to investigate getting it to work... vaguely:

import { console } from "console-fail-test";

// ...

expect(console.log.mock.calls).toMatchInlineSnapshot();

Additional Info

No response

@JoshuaKGoldberg JoshuaKGoldberg added the type: feature New enhancement or request 🚀 label Sep 5, 2023
@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Sep 5, 2023
@JoshuaKGoldberg JoshuaKGoldberg added the status: needs investigation Further research required...? 🔎 label Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs investigation Further research required...? 🔎 type: feature New enhancement or request 🚀
Projects
None yet
Development

No branches or pull requests

1 participant