asynchronous摩卡testing(与Chai断言库)应该失败,但被标记为通过

我已经在TypeScript中使用mochatesting框架和chai断言库(我对这三者都是新手)写了一些testing,并看到引发了一个错误,并在下面的代码中调用了assert.fail()。 但是,testing仍然被标记为通过。 我很困惑,为什么会这样呢,如果我在承诺上做错了什么。 另外,如下所示,还有一个UnhandledPromiseRejectionWarning。 我不明白为什么这被标记为未处理,因为我已经包括一个catch块。 我将不胜感激关于如何解决这个问题的build议,谢谢!

User.all() .then((users) => { expect(users.length).to.equal(0); return User.create('test@test.email', '12345', 'test', true, true); }) .then(() => { return User.all(); }) .then((users) => { expect(users.length).to.equal(1); }) .catch((error) => { assert.fail(); }); 

debugging控制台

  ✓ should create a new record with existing e-mail in the database (node:29903) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): AssertionError: assert.fail() (node:29903) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 

debugging控制台

正如本杰明·格鲁恩鲍姆(Benjamin Gruenbaum)在上面所说的那样,通过确保这个块返回一个承诺,

 it('should create a new record', () => { return User.all() .then((users) => { expect(users.length).to.equal(0); return User.create('test@test.email', '12345', 'test', true, true); }) .then(() => { return User.all(); }) .then((users) => { expect(users.length).to.equal(1); }) .catch((error) => { assert.fail(); }); });