Перейти к основной части
Version: Далее

Глобальные значения

В скриптах тестирования, Jest создает эти функции и объекты в глобальной области видимости. Вам не нужно ничего импортировать или подключать к скрипту для работы с этими функциями и объектами. Однако, если вы предпочитаете импорт, вы можете импортировать {describe, expect, test} из '@jest/globals'.

Методы#


Справка#

afterAll(fn, timeout)#

Выполняет функцию после всех тестов в этом файле. Если функция возвращает промис или является генератором, Jest ждет пока промис разрешится, а затем запускает тесты.

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

Например:

Например:

const globalDatabase = makeGlobalDatabase();
function cleanUpDatabase(db) {
db.cleanUp();
}
afterAll(() => {
cleanUpDatabase(globalDatabase);
});
test('может найти запись', () => {
return globalDatabase.find('запись', {}, results => {
expect(results.length).toBeGreaterThan(0);
});
});
test('может добавить запись', () => {
return globalDatabase.insert('запись', makeThing(), response => {
expect(response.success).toBeTruthy();
});
});

Если afterAll находится внутри блока describe, то он запускается в конце блока describe.

Если вы хотите производить очистку после каждого теста, а не после всех тестов, то вместо этого используйте afterEach.

Это может быть полезно, если вы хотите очистить некоторое временное состояние создаваемое каждым тестом.

afterEach(fn, timeout)#

Выполняет функцию после каждого теста в файле. Если функция возвращает промис или является генератором, Jest ждет пока промис разрешится, а затем запускает тесты.

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

Например:

Например:

const globalDatabase = makeGlobalDatabase();
function cleanUpDatabase(db) {
db.cleanUp();
}
afterEach(() => {
cleanUpDatabase(globalDatabase);
});
test('може найти запись', () => {
return globalDatabase.find('запись', {}, results => {
expect(results.length).toBeGreaterThan(0);
});
});
test('может добавить запись', () => {
return globalDatabase.insert('запись', makeThing(), response => {
expect(response.success).toBeTruthy();
});
});

Если afterEach находится внутри блока describe, то он запускается только после каждого теста внутри блока describe.

Если вы хотите провести очистку только один раз, после всех тестов, используйте afterAll.

Если вы хотите провести очистку только один раз, после всех тестов, используйте afterAll.

beforeAll(fn, timeout)#

Выполняет функцию перед запуском каждого теста в этом файле. Если функция возвращает промис или является генератором, Jest ждет пока промис разрешится, а затем запускает тест.

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

Например:

Например:

const globalDatabase = makeGlobalDatabase();
beforeEach(() => {
// Очищает базу данных и добавляет данные тестирования.
// Jest будет ждать завершения этого Promise перед запуском тестов.
return globalDatabase.clear().then(() => {
return globalDatabase.insert({testData: 'foo'});
});
});
test('can find things', () => {
return globalDatabase.find('thing', {}, results => {
expect(results.length).toBeGreaterThan(0);
});
});
test('can insert a thing', () => {
return globalDatabase.insert('thing', makeThing(), response => {
expect(response.success).toBeTruthy();
});
});

Здесь beforeAll гарантирует, что база данных настроена, перед запуском тестов. If setup was synchronous, you could do this without beforeAll. Ключевым является то, что Jest будет ждать разрешения промиса, поэтому вы можете установить асинхронно.

Если вместо запуска перед выполнением всех тестов, вы хотите что-то запускать перед каждым тестом, то используйте beforeEach.

Если вместо запуска перед выполнением всех тестов, вы хотите что-то запускать перед каждым тестом, то используйте beforeEach.

beforeEach(fn, timeout)#

Выполняет функцию перед выполнением тестов в текущем файле. Если функция возвращает промис или является генератором, Jest ждет пока промис разрешится, а затем запускает тесты.

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

This is often useful if you want to reset some global state that will be used by many tests.

Например:

const globalDatabase = makeGlobalDatabase();
beforeEach(() => {
// Clears the database and adds some testing data.
// Jest будет ждать завершения этого Promise перед запуском тестов.
return globalDatabase.clear().then(() => {
return globalDatabase.insert({testData: 'foo'});
});
});
// Since we only set up the database once in this example, it's important
// that our tests don't modify it. test('can find things', () => {
return globalDatabase.find('thing', {}, results => {
expect(results.length).toBeGreaterThan(0);
});
});

Here the beforeEach ensures that the database is reset for each test.

If beforeEach is inside a describe block, it runs for each test in the describe block.

If you only need to run some setup code once, before any tests run, use beforeAll instead.

describe(name, fn)#

describe(name, fn) группирует связанные по логике тесты в один блок. Например, если у вас есть объект myBeverage, который должен быть вкусным (ключ "delicious"), но не кислым (ключ "sour"), вы можете протестировать его следующим образом:

const myBeverage = {
delicious: true,
sour: false,
};
describe('my beverage', () => {
test('is delicious', () => {
expect(myBeverage.delicious).toBeTruthy();
});
test('is not sour', () => {
expect(myBeverage.sour).toBeFalsy();
});
});

Это не обязательно, вы можете писать тесты в глобальном уровне. Но это может быть удобно, группировать некоторые тесты вместе.

You can also nest describe blocks if you have a hierarchy of tests:

const binaryStringToNumber = binString => {
if (!/^[01]+$/.test(binString)) {
throw new CustomError('Not a binary number.');
}
return parseInt(binString, 2);
};
describe('binaryStringToNumber', () => {
describe('given an invalid binary string', () => {
test('composed of non-numbers throws CustomError', () => {
expect(() => binaryStringToNumber('abc')).toThrowError(CustomError);
});
test('with extra whitespace throws CustomError', () => {
expect(() => binaryStringToNumber(' 100')).toThrowError(CustomError);
});
});
describe('given a valid binary string', () => {
test('returns the correct number', () => {
expect(binaryStringToNumber('100')).toBe(4);
});
});
});

describe.each(table)(name, fn, timeout)#

Используйте describe.each если собираетесь дублировать одинаковые тесты с разными данными. describe.each позволяет вам писать наборы тестов один раз и передавать в него данные.

describe.each is available with two APIs:

1. describe.each(table)(name, fn, timeout)#

  • table: Массив of Arrays with the arguments that are passed into the fn for each row.
    • Примечание. Если вы передадите одномерный массив примитивов, внутри он преобразуется многомерный, например [1, 2, 3] -> [[1], [2], [3]]
  • наименование: Строка название теста.
    • Generate unique test titles by positionally injecting parameters with printf formatting:
      • %p - pretty-format.
      • %s- String.
      • %d- Number.
      • %i - Integer.
      • %f - Floating point value.
      • %j - JSON.
      • %o - Object.
      • %# - Index of the test case.
      • %% - single percent sign ('%'). This does not consume an argument.
    • Or generate unique test titles by injecting properties of test case object with $variable
      • To inject nested object values use you can supply a keyPath i.e. $variable.path.to.value
      • You can use $# to inject the index of the test case
      • You cannot use $variable with the printf formatting except for %%
  • fn: Function the suite of tests to be ran, this is the function that will receive the parameters in each row as function arguments.
  • Optionally, you can provide a timeout (in milliseconds) for specifying how long to wait for each row before aborting. Note: The default timeout is 5 seconds.

Пример:

describe.each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
])('.add(%i, %i)', (a, b, expected) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
});
test(`returned value not be greater than ${expected}`, () => {
expect(a + b).not.toBeGreaterThan(expected);
});
test(`returned value not be less than ${expected}`, () => {
expect(a + b).not.toBeLessThan(expected);
});
});
describe.each([
{a: 1, b: 1, expected: 2},
{a: 1, b: 2, expected: 3},
{a: 2, b: 1, expected: 3},
])('.add($a, $b)', ({a, b, expected}) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
});
test(`returned value not be greater than ${expected}`, () => {
expect(a + b).not.toBeGreaterThan(expected);
});
test(`returned value not be less than ${expected}`, () => {
expect(a + b).not.toBeLessThan(expected);
});
});

2. describe.each`table`(name, fn, timeout)#

  • table: Tagged Template Literal
    • First row of variable name column headings separated with |
    • One or more subsequent rows of data supplied as template literal expressions using ${value} syntax.
  • name: String the title of the test suite, use $variable to inject test data into the suite title from the tagged template expressions, and $# for the index of the row.
    • To inject nested object values use you can supply a keyPath i.e. $variable.path.to.value
  • fn: Function the suite of tests to be ran, this is the function that will receive the test data object.
  • Optionally, you can provide a timeout (in milliseconds) for specifying how long to wait for each row before aborting. Note: The default timeout is 5 seconds.

Пример:

describe.each`
a | b | expected
${1} | ${1} | ${2}
${1} | ${2} | ${3}
${2} | ${1} | ${3}
`('$a + $b', ({a, b, expected}) => {
test(`возвращает ${expected}`, () => {
expect(a + b).toBe(expected);
});
test(`возвращаемое значение не должно быть больше чем ${expected}`, () => {
expect(a + b).not.toBeGreaterThan(expected);
});
test(`возвращаемое значение не должно быть меньше чем ${expected}`, () => {
expect(a + b).not.toBeLessThan(expected);
});
});

describe.only(name, fn)#

Also under the alias: fdescribe(name, fn)

You can use describe.only if you want to run only one describe block:

describe.only('мой напиток', () => {
test('вкусный', () => {
expect(myBeverage.delicious).toBeTruthy();
});
test('не кислый', () => {
expect(myBeverage.sour).toBeFalsy();
});
});
describe('мои другие напитки', () => {
// будет пропущено
});

describe.only.each(table)(name, fn)#

Also under the aliases: fdescribe.each(table)(name, fn) and fdescribe.each`table`(name, fn)

Use describe.only.each if you want to only run specific tests suites of data driven tests.

describe.only.each is available with two APIs:

describe.only.each(table)(name, fn)#

describe.only.each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
])('.add(%i, %i)', (a, b, expected) => {
test(`возвращаемое значение ${expected}`, () => {
expect(a + b).toBe(expected);
});
});
test('не будет запущено', () => {
expect(1 / 0).toBe(Infinity);
});

describe.only.each`table`(name, fn)#

describe.only.each`
a | b | expected
${1} | ${1} | ${2}
${1} | ${2} | ${3}
${2} | ${1} | ${3}
`('возвращаемое значение $expected когда $a прибавлено к $b', ({a, b, expected}) => {
test('пройдет', () => {
expect(a + b).toBe(expected);
});
});
test('не будет пройдено', () => {
expect(1 / 0).toBe(Infinity);
});

describe.skip(name, fn)#

Also under the alias: xdescribe(name, fn)

You can use describe.skip if you do not want to run a particular describe block:

describe('мой напиток', () => {
test('вкусный', () => {
expect(myBeverage.delicious).toBeTruthy();
});
test('не кислый', () => {
expect(myBeverage.sour).toBeFalsy();
});
});
describe.skip('мои другие напитки', () => {
// ... будет пропущено
});

Using describe.skip is often a cleaner alternative to temporarily commenting out a chunk of tests.

describe.skip.each(table)(name, fn)#

Also under the aliases: xdescribe.each(table)(name, fn) and xdescribe.each`table`(name, fn)

Use describe.skip.each if you want to stop running a suite of data driven tests.

describe.skip.each is available with two APIs:

describe.skip.each(table)(name, fn)#

describe.skip.each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
])('.add(%i, %i)', (a, b, expected) => {
test(`возвращаемое значение ${expected}`, () => {
expect(a + b).toBe(expected); // will not be ran
});
});
test('будет запущен', () => {
expect(1 / 0).toBe(Infinity);
});

describe.skip.each`table`(name, fn)#

describe.skip.each`
a | b | expected
${1} | ${1} | ${2}
${1} | ${2} | ${3}
${2} | ${1} | ${3}
`('возвращаемое значение $expected когда $a прибавлено к $b', ({a, b, expected}) => {
test('не будет запущено', () => {
expect(a + b).toBe(expected); // will not be ran
});
});
test('будет запущено', () => {
expect(1 / 0).toBe(Infinity);
});

test(name, fn, timeout)#

Also under the alias: it(name, fn, timeout)

All you need in a test file is the test method which runs a test. For example, let's say there's a function inchesOfRain() that should be zero. Your whole test could be:

test('дождя не было', () => {
expect(inchesOfRain()).toBe(0);
});

The first argument is the test name; the second argument is a function that contains the expectations to test. The third argument (optional) is timeout (in milliseconds) for specifying how long to wait before aborting. Note: The default timeout is 5 seconds.

Note: If a promise is returned from test, Jest will wait for the promise to resolve before letting the test complete. Jest will also wait if you provide an argument to the test function, usually called done. This could be handy when you want to test callbacks. See how to test async code here.

For example, let's say fetchBeverageList() returns a promise that is supposed to resolve to a list that has lemon in it. You can write:

test('содержит ли лимон', () => {
return fetchBeverageList().then(list => {
expect(list).toContain('lemon');
});
});

Even though the call to test will return right away, the test doesn't complete until the promise resolves as well.

test.concurrent(name, fn, timeout)#

Also under the alias: it.concurrent(name, fn, timeout)

Use test.concurrent if you want the test to run concurrently.

Note: test.concurrent is considered experimental - see here for details on missing features and other issues

The first argument is the test name; the second argument is an asynchronous function that contains the expectations to test. The third argument (optional) is timeout (in milliseconds) for specifying how long to wait before aborting. Note: The default timeout is 5 seconds.

test.concurrent('addition of 2 numbers', async () => {
expect(5 + 3).toBe(8);
});
test.concurrent('subtraction 2 numbers', async () => {
expect(5 - 3).toBe(2);
});

Note: Use maxConcurrency in configuration to prevents Jest from executing more than the specified amount of tests at the same time

test.concurrent.each(table)(name, fn, timeout)#

Also under the alias: it.concurrent.each(table)(name, fn, timeout)

Используйте test.concurrent.each если собираетесь дублировать одинаковые тесты с разными данными. test.each allows you to write the test once and pass data in, the tests are all run asynchronously.

test.concurrent.each is available with two APIs:

1. test.concurrent.each(table)(name, fn, timeout)#

  • table: Массив of Arrays with the arguments that are passed into the test fn for each row.
    • Примечание. Если вы передадите одномерный массив примитивов, внутри он преобразуется многомерный, например [1, 2, 3] -> [[1], [2], [3]]
  • наименование: Строка the title of the test block.
    • Generate unique test titles by positionally injecting parameters with printf formatting:
      • %p - pretty-format.
      • %s- String.
      • %d- Number.
      • %i - Integer.
      • %f - Floating point value.
      • %j - JSON.
      • %o - Object.
      • %# - Index of the test case.
      • %% - single percent sign ('%'). This does not consume an argument.
  • fn: Function the test to be ran, this is the function that will receive the parameters in each row as function arguments, this will have to be an asynchronous function.
  • Optionally, you can provide a timeout (in milliseconds) for specifying how long to wait for each row before aborting. Note: The default timeout is 5 seconds.

Пример:

test.concurrent.each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
])('.add(%i, %i)', async (a, b, expected) => {
expect(a + b).toBe(expected);
});

2. test.concurrent.each`table`(name, fn, timeout)#

  • table: Tagged Template Literal
    • First row of variable name column headings separated with |
    • One or more subsequent rows of data supplied as template literal expressions using ${value} syntax.
  • наименование: Строка the title of the test, use $variable to inject test data into the test title from the tagged template expressions.
    • To inject nested object values use you can supply a keyPath i.e. $variable.path.to.value
  • fn: Function the test to be ran, this is the function that will receive the test data object, this will have to be an asynchronous function.
  • Optionally, you can provide a timeout (in milliseconds) for specifying how long to wait for each row before aborting. Note: The default timeout is 5 seconds.

Пример:

test.concurrent.each`
a | b | expected
${1} | ${1} | ${2}
${1} | ${2} | ${3}
${2} | ${1} | ${3}
`('returns $expected when $a is added $b', async ({a, b, expected}) => {
expect(a + b).toBe(expected);
});

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

Also under the alias: it.concurrent.only.each(table)(name, fn)

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

test.concurrent.only.each is available with two APIs:

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

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

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

test.concurrent.only.each`
a | b | expected
${1} | ${1} | ${2}
${1} | ${2} | ${3}
${2} | ${1} | ${3}
`('returns $expected when $a is added $b', async ({a, b, expected}) => {
expect(a + b).toBe(expected);
});
test('will not be ran', () => {
expect(1 / 0).toBe(Infinity);
});

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

Also under the alias: it.concurrent.skip.each(table)(name, fn)

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

test.concurrent.skip.each is available with two APIs:

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

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

test.concurrent.skip.each`table`(name, fn)#

test.concurrent.skip.each`
a | b | expected
${1} | ${1} | ${2}
${1} | ${2} | ${3}
${2} | ${1} | ${3}
`('returns $expected when $a is added $b', async ({a, b, expected}) => {
expect(a + b).toBe(expected); // will not be ran
});
test('will be ran', () => {
expect(1 / 0).toBe(Infinity);
});

test.each(table)(name, fn, timeout)#

Можно воспользоваться алиасами: it.each(table)(name, fn) и it.each`table`(name, fn)

Используйте test.each если собираетесь дублировать одинаковые тесты с разными данными. test.each позволяет вам писать тест один раз и передавать в него данные.

test.each is available with two APIs:

1. test.each(table)(name, fn, timeout)#

  • table: Массив of Arrays with the arguments that are passed into the test fn for each row.
    • Примечание. Если вы передадите одномерный массив примитивов, внутри он преобразуется многомерный, например [1, 2, 3] -> [[1], [2], [3]]
  • наименование: Строка the title of the test block.
    • Generate unique test titles by positionally injecting parameters with printf formatting:
      • %p - pretty-format.
      • %s- String.
      • %d- Number.
      • %i - Integer.
      • %f - Floating point value.
      • %j - JSON.
      • %o - Object.
      • %# - Index of the test case.
      • %% - single percent sign ('%'). This does not consume an argument.
    • Or generate unique test titles by injecting properties of test case object with $variable
      • To inject nested object values use you can supply a keyPath i.e. $variable.path.to.value
      • You can use $# to inject the index of the test case
      • You cannot use $variable with the printf formatting except for %%
  • fn: Function the test to be ran, this is the function that will receive the parameters in each row as function arguments.
  • Optionally, you can provide a timeout (in milliseconds) for specifying how long to wait for each row before aborting. Note: The default timeout is 5 seconds.

Пример:

test.each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
])('.add(%i, %i)', (a, b, expected) => {
expect(a + b).toBe(expected);
});
test.each([
{a: 1, b: 1, expected: 2},
{a: 1, b: 2, expected: 3},
{a: 2, b: 1, expected: 3},
])('.add($a, $b)', ({a, b, expected}) => {
expect(a + b).toBe(expected);
});

2. test.each`table`(name, fn, timeout)#

  • table: Tagged Template Literal
    • First row of variable name column headings separated with |
    • One or more subsequent rows of data supplied as template literal expressions using ${value} syntax.
  • наименование: Строка the title of the test, use $variable to inject test data into the test title from the tagged template expressions.
    • To inject nested object values use you can supply a keyPath i.e. $variable.path.to.value
  • fn: Function the test to be ran, this is the function that will receive the test data object.
  • Optionally, you can provide a timeout (in milliseconds) for specifying how long to wait for each row before aborting. Note: The default timeout is 5 seconds.

Пример:

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

test.only(name, fn, timeout)#

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

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.

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

For example, let's say you had these tests:

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.each`table`(name, fn) and fit.each`table`(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.each`table`(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)

When you are maintaining a large codebase, you may sometimes find a test that is temporarily broken for some reason. 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.

For example, let's say you had these tests:

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

Only the "it is raining" test will run, since the other test is run with test.skip.

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.each`table`(name, fn), xit.each`table`(name, fn) and xtest.each`table`(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.each`table`(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. 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.

API#

  • name: String the title of the test plan.

Пример:

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