describe/it 语法


describe/it syntax】

运行测试也可以使用 describe 来声明一个测试套件,使用 it 来声明一个测试。测试套件用于组织和分组相关的测试。ittest 的别名,但不会传入测试上下文,因为嵌套是通过测试套件来实现的。

【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 an alias for test, except there is no test context passed, since nesting is done using suites.】

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

describeit 是从 node:test 模块中导入的。

import { describe, it } from 'node:test';const { describe, it } = require('node:test');