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 模块导入的。
¥describe and it are imported from the node:test module.
import { describe, it } from 'node:test';const { describe, it } = require('node:test');