- Objective: - Breadcrumb: node.js # 概念阐释 ## 语义 `describe...it` 是mocha中最常用的2个函数,用于构建测试的组织结构。 - `describe` 对测试的特定部分进行描述,与回调函数,里面包含测试用例或更多的`describe`**嵌套块**; - `it` 用于定一个实际的测试用例; - `assert` 断言,用来检查代码的行为是否符合预期。 ## 语法 ```js describe( '描述', ()=>{ it('测试用例描述',()=>{}); }); ``` # 实例 ```js const assert = require('assert'); const sum = require('./sum'); describe('Sum function', function() { it('should return 4 when adding 2 and 2', function() { assert.equal(sum(2, 2), 4); }); it('should return 0 when no arguments are passed', function() { assert.equal(sum(), 0); }); }); ``` # 相关内容 # 问题 1. 解读以下代码,复写一遍 ```js const assert = require('assert'); const sum = require('./sum'); describe('Sum function', function() { it('should return 4 when adding 2 and 2', function() { assert.equal(sum(2, 2), 4); }); it('should return 0 when no arguments are passed', function() { assert.equal(sum(), 0); }); }); ``` ```js describe('Math', () => {   describe('.max', () => {     it('returns the argument with the highest value', () => {       // Your test goes here     });     it('returns -Infinity when no arguments are provided', () => {       // Your test goes here     });   }); }); ``` # 问题答案 # 参考资料