Skip, Todo, and Only

This is particularly handy during development for isolating a failing test or temporarily disabling a broken one without deleting it.

You can use the .only, .todo, .skip modifiers to handle these.

Skip and Todo

.skip and .todo work in very similar ways. If they are attached to a test() or it() call, those tests won't run.

Use .skip for temporarily disabling tests and .todo for placeholder tests you plan to implement later.

You can also add this to a describe() block, so nothing in that block will run.

test('this will run', () => {
  expect(1).toBe(1);
});
test.skip('this will not run (it would fail anyway)', () => {
  expect(1).toBe(9);
});

// Note: .todo() has no second argument containing a test function.
// It's just a placeholder with a test name.
test.todo(
  'some test that you know you have to write'
);

And this is how to use it with a describe block:

describe('this will run', () => {
  test('this runs ok', () => {
    expect(1).toBe(1);
  });
});

describe.skip('nothing inside of here will run', () => {
  test('this will not run', () => {
    // doesn't matter what is in here, it won't run
  });
});

Run only a certain test with .only

This works in the opposite way - if there is a .only modifier in your test file, then that will be the only thing that runs

Remember to remove .only modifiers before committing code, as they will prevent other tests from running in CI/CD pipelines.

test.only('this will run', () => {
  expect(1).toBe(1);
});

test('this will not run', () => {
  expect(1).toBe(1);
});

Again you can apply it to describe blocks too like describe.only('...', () => {}).

Lesson Task

Use a mix of test.only(...) and test.skip(...) to control which tests run.

Ready to try running tests for this lesson?