全局设定·续3

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);});

1. test.only(name, fn, timeout)

Also under the aliases: it.only(name, fn, timeout), and fit(name, fn, timeout)

当你维护一个很大的代码库时,有时可能会发现一个由于某种原因被暂时破坏的测试。 If you want to skip running this test, but you don’t want to delete this code, you can use test.skip to specify some tests to skip.

Optionally, you can provide a timeout (in milliseconds) for specifying how long to wait before aborting. Note: The default timeout is 5 seconds. Note: The default timeout is 5 seconds.

比如说,你有这些测试︰

test.only('it is raining', () => {  expect(inchesOfRain()).toBeGreaterThan(0);});test('it is not snowing', () => {  expect(inchesOfSnow()).toBe(0);});

Only the “it is raining” test will run in that test file, since it is run with test.only.

Usually you wouldn’t check code using test.only into source control - you would use it for debugging, and remove it once you have fixed the broken tests.

test.only.each(table)(name, fn)

Also under the aliases: it.only.each(table)(name, fn), fit.each(table)(name, fn), it.only.eachtable(name, fn) and fit.eachtable(name, fn)

Use test.only.each if you want to only run specific tests with different test data.

test.only.each is available with two APIs:

test.only.each(table)(name, fn)

test.only.each([  [1, 1, 2],  [1, 2, 3],  [2, 1, 3],])('.add(%i, %i)', (a, b, expected) => {  expect(a + b).toBe(expected);});test('will not be ran', () => {  expect(1 / 0).toBe(Infinity);});

test.only.eachtable(name, fn)

test.only.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);});test('will not be ran', () => {  expect(1 / 0).toBe(Infinity);});

test.skip(name, fn)

Also under the aliases: it.skip(name, fn), xit(name, fn), and xtest(name, fn)

当你维护一个很大的代码库时,有时可能会发现一个由于某种原因被暂时破坏的测试。 If you want to skip running this test, but you don’t want to delete this code, you can use test.skip to specify some tests to skip.

比如说,你有这些测试︰

test('it is raining', () => {  expect(inchesOfRain()).toBeGreaterThan(0);});test.skip('it is not snowing', () => {  expect(inchesOfSnow()).toBe(0);});

When you are debugging a large test file, you will often only want to run a subset of tests. You can use .only to specify which tests are the only ones you want to run in that test file.

You could comment the test out, but it’s often a bit nicer to use test.skip because it will maintain indentation and syntax highlighting.

test.skip.each(table)(name, fn)

Also under the aliases: it.skip.each(table)(name, fn), xit.each(table)(name, fn), xtest.each(table)(name, fn), it.skip.eachtable(name, fn), xit.eachtable(name, fn) and xtest.eachtable(name, fn)

Use test.skip.each if you want to stop running a collection of data driven tests.

test.skip.each is available with two APIs:

test.skip.each(table)(name, fn)

test.skip.each([  [1, 1, 2],  [1, 2, 3],  [2, 1, 3],])('.add(%i, %i)', (a, b, expected) => {  expect(a + b).toBe(expected); // will not be ran});test('will be ran', () => {  expect(1 / 0).toBe(Infinity);});

test.skip.eachtable(name, fn)

test.skip.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); // will not be ran});test('will be ran', () => {  expect(1 / 0).toBe(Infinity);});

test.todo(name)

Also under the alias: it.todo(name)

Use test.todo when you are planning on writing tests. Use test.todo when you are planning on writing tests. These tests will be highlighted in the summary output at the end so you know how many tests you still need todo.

Note: If you supply a test callback function then the test.todo will throw an error. If you have already implemented the test and it is broken and you do not want it to run, then use test.skip instead. If you have already implemented the test and it is broken and you do not want it to run, then use test.skip instead.

API

  • name: String the title of the test plan.

Example:

const add = (a, b) => a + b;test.todo('add should be associative');