diff --git a/test/test.spec.js b/test/test.spec.js index 3417042..9a26eaa 100644 --- a/test/test.spec.js +++ b/test/test.spec.js @@ -1,34 +1,60 @@ -var assert = require('assert') - -describe('Array', function() { - describe('#indexOf()', function() { - test('当value不在数组中应当返回-1', function() { - assert.equal(-1, [1, 2, 3]/* 填空题 */) - }) - }) -}) - -describe('assert', function () { - test('a和b应当深度相等', function () { +var assert = require("node:assert/strict"); + +describe("Array", function () { + describe("#indexOf()", function () { + test("当value不在数组中应当返回-1", function () { + function tmp(value) { + return [1, 2, 3].indexOf(value); + } + assert.equal(tmp(10), -1); + }); + }); +}); + +describe("assert", function () { + test("a和b应当深度相等", function () { var a = { c: { - e: 1 - } - } + e: 1, + }, + }; var b = { c: { - e: 1 + e: 1, + }, + }; + + function tmp(obj) { + const deeps = new Set(); + + for (let key of Reflect.ownKeys(obj)) { + const value = obj[key]; + if (typeof value === "object") { + deeps.add(1 + tmp(value)); + } else { + deeps.add(1); + } } + + return Math.max(...deeps); } + // 修改下面代码使得满足测试描述 - assert.equal(a, b) - }) + assert.equal(tmp(a), tmp(b)); + }); - test('可以捕获并验证函数fn的错误', function () { + test("可以捕获并验证函数fn的错误", function () { function fn() { xxx; } - // 修改下面代码使得满足测试描述 - fn() - }) -}) \ No newline at end of file + + assert.throws( + () => { + fn(); + }, + { + name: "ReferenceError", + } + ); + }); +});