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

Macro #use() feature request #1456

Open
skeggse opened this issue Jul 15, 2017 · 4 comments
Open

Macro #use() feature request #1456

skeggse opened this issue Jul 15, 2017 · 4 comments

Comments

@skeggse
Copy link

skeggse commented Jul 15, 2017

Description

I'd like to see a slightly simpler means to use the same macro for a large number of tests. Instead of specifying the macro at every call-site, it might be nice to have a test.use(macro) function that produces a new test function that will apply the macro to every invocation.

Test Source

import test from 'ava';

function macro(t, input, expected) {
	t.is(eval(input), expected);
}

const check = test.use(macro);

check('2 + 2 = 4', '2 + 2', 4);
check('2 * 3 = 6', '2 * 3', 6);

const title = (providedTitle, input, expected) => `${providedTitle} ${input} = ${expected}`.trim();

const checkIt = test.use(macro, title);

checkIt('2 + 2', 4);
checkIt('2 * 3', 6);

If interested, I might find the time to write a PR for this feature.

@avajs avajs deleted a comment from 120687 Jul 15, 2017
@novemberborn
Copy link
Member

I like it!

IMO the title function should remain on the macro (so no test.use(macro, title)).

What would check.use(otherMacro) do? Perhaps throw an exception?

@avajs/core?

@sindresorhus
Copy link
Member

I like it too, but I think it should be named test.macro() for clarity instead of test.use().

@novemberborn
Copy link
Member

The test API should be available on these produced functions, e.g. check.skip(), check.serial(), check.cb().

Though perhaps not check.before(), check.after() etc.

@novemberborn
Copy link
Member

I think this could be test.curry(). Will investigate as part of #2435.

@novemberborn novemberborn self-assigned this May 25, 2020
@novemberborn novemberborn removed their assignment Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants