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] add a expect.toFail equivalent #20518

Closed
A-ZC-Lau opened this issue Jan 31, 2023 · 5 comments · Fixed by #20596
Closed

[Feature] add a expect.toFail equivalent #20518

A-ZC-Lau opened this issue Jan 31, 2023 · 5 comments · Fixed by #20596
Assignees
Labels

Comments

@A-ZC-Lau
Copy link

So we have a .toPass now, and I was wondering if we could have a .toFail equivalent.

For example, I have the function which tests an array of lessThan:

function LESS_THAN (input : [number, number][]) {
	for (const row of input) {
		test.expect(row[0]).toBeLessThan(row[1]);
	}
}

const passing = [ [1, 2], [3, 4], [5, 6] ]
test("expect to pass", () => LESS_THAN(passing));

const failing = [ [1, 2], [4, 3], [5, 6] ];
test("expect to fail", () => LESS_THAN(failing));
@dgozman
Copy link
Contributor

dgozman commented Jan 31, 2023

@A-ZC-Lau Perhaps, expect(fn).not.toPass() would work for you?

@A-ZC-Lau
Copy link
Author

@dgozman my tests still fail, the "not" doesn't seem to have any effect.

@dgozman
Copy link
Contributor

dgozman commented Jan 31, 2023

@A-ZC-Lau Could you please share the exact snippet you run? The original snippet fails, but that's expected. How do you want to use toFail here? I thought you'd use toPass and not.toPass, but sounds like you are doing something else?

@A-ZC-Lau
Copy link
Author

@dgozman

function CHECK_BLOCK_TIMING (vtt : any) {
	for (const file of vtt) {
		let previous : null | number = null;
		for (const block of file) {
			if (previous !== null) {
				test.expect.soft(previous, JSON.stringify(block)).toBeLessThanOrEqual(block[1]);
			}
			test.expect.soft(block[1], JSON.stringify(block)).toBeLessThanOrEqual(block[2]);
			previous = block[2];
		}
	}
}
test.describe("CHECK_BLOCK_TIMING", function () {
	test("failed inner timing", async function () {
		const failTiming = [
			[
				["Wales",2.1,2.5,1],
				["and",2.6,2.3,1],
				["Victoria",2.6,3.2,1],
			],
		];
		test.expect(() => {
			Helpers.CHECK_BLOCK_TIMING(failTiming);
		}).not.toPass({timeout : 5000});
	});
	test("failed in between timing", async function () {
		const failTiming = [
			[
				["Wales",2.1,2.5,1],
				["and",2.5,2.6,1],
				["Victoria",2.5,3.2,1],
			],
		];
		test.expect(() => {
			Helpers.CHECK_BLOCK_TIMING(failTiming);
		}).not.toPass({timeout : 5000});
	});
});

I still get a failed test, e.g.
Screenshot 2023-02-01 at 10 11 29 am

Let me know if a codesandbox is needed.

@dgozman
Copy link
Contributor

dgozman commented Feb 1, 2023

Thank you, I can repro.

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

Successfully merging a pull request may close this issue.

3 participants