Creates a test closure.
The name of your test
Optional
fn: ProvidesCallbackThe function for your test
Optional
timeout: numberThe timeout for an async function test
Experimental and should be avoided.
Use if you keep duplicating the same test with different data. .each
allows you to write the
test once and pass data in.
.each
is available with two APIs:
test.each(table)(name, fn)
table
: Array of Arrays with the arguments that are passed into the test fn for each row.name
: String the title of the test block.fn
: Function the test to be run, this is the function that will receive the parameters in each row as function arguments.test.each table(name, fn)
table
: Tagged Template Literalname
: String the title of the test, use $variable
to inject test data into the test title from the tagged template expressions.fn
: Function the test to be run, this is the function that will receive the test data object.// API 1
test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%i, %i)',
(a, b, expected) => {
expect(a + b).toBe(expected);
},
);
// API 2
test.each`
a | b | expected
${1} | ${1} | ${2}
${1} | ${2} | ${3}
${2} | ${1} | ${3}
`('returns $expected when $a is added $b', ({a, b, expected}) => {
expect(a + b).toBe(expected);
});
Mark this test as expecting to fail.
Only available in the default jest-circus
runner.
Only runs this test in the current file.
Skips running this test in the current file.
Sketch out which tests to write in the future.
Creates a test closure