Skip to content

Macro #use() feature request #1456

Open
@skeggse

Description

@skeggse

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions