A vital testing skill is focusing a test. When iterating on a failing test, we want that test under microscope.
The way I do this in JavaScript is .only:
import {describe, expect, test} from 'vitest';
import {sum} from './sum.js';
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
describe.only('adding fours', () => {
test('adds 4 + 4 to equal 8', () => {
expect(sum(4, 4)).toBe(8);
});
});
When this test runs, only the describe will run, the other is skipped.
This works on test, it, and describe, in Jest, Vitest, and probably any JS
test framework you try.
There are alternatives, including skip, fit or fdescribe, command-line
flags. To me, they’re all less memorable and ergonomic than .only.