describe/it 语法
🌐 describe/it syntax
运行测试也可以使用 describe 来声明一个测试套件,使用 it 来声明一个测试。测试套件用于组织和分组相关的测试。it 是 test() 的简写。
🌐 Running tests can also be done using describe to declare a suite
and it to declare a test.
A suite is used to organize and group related tests together.
it is a shorthand for test().
describe('A thing', () => {
it('should work', () => {
assert.strictEqual(1, 1);
});
it('should be ok', () => {
assert.strictEqual(2, 2);
});
describe('a nested thing', () => {
it('should work', () => {
assert.strictEqual(3, 3);
});
});
}); describe 和 it 是从 node:test 模块中导入的。
import { describe, it } from 'node:test';const { describe, it } = require('node:test');