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

Expose current test instance to test.meta #2017

Closed
szmarczak opened this issue Jan 14, 2019 · 4 comments
Closed

Expose current test instance to test.meta #2017

szmarczak opened this issue Jan 14, 2019 · 4 comments
Labels

Comments

@szmarczak
Copy link

In last release (1.1.0) there was added test.meta feature.

I'd like to propose test.meta.currentTest which points to the current test instance. Use case:

-const compare = (t, entries, goal) => {
+const compare = (entries, goal) => {
+   const t = test.meta.currentTest;
	if (Array.isArray(entries)) {
		entries = entries.map(entry => {
			t.true(typeof entry.expires === 'number');
			return {
				address: entry.address,
				family: entry.family
			};
		});
	} else {
		delete entries.expires;
	}

	t.deepEqual(entries, goal);
};

test('demo', t => {
	const entries = getEntries();
-	compare(t, entries, [
+   compare(entries, [
		{address: '1.2.3.4', family: 4},
		{address: }
	]);
});
@novemberborn
Copy link
Member

I don't think that would work for asynchronous tests: multiple tests would be running concurrently so there wouldn't be any one currentTest.

Besides the code sample, could you elaborate on your use case?

@szmarczak
Copy link
Author

szmarczak commented Jan 14, 2019

I don't think that would work for asynchronous tests: multiple tests would be running concurrently so there wouldn't be any one currentTest.

Hmm, that's true, unfortunately.

Besides the code sample, could you elaborate on your use case?

You just need to pass the test instance every time, which is quite irritating. I often did compare(entries, ...) instead of compare(t, entries, ...).

@novemberborn
Copy link
Member

We are open to being able to install additional assertions on t: #1094

@szmarczak
Copy link
Author

@novemberborn That whould be the right thing :)

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

No branches or pull requests

2 participants