简体   繁体   English

摩卡:无法读取未定义的属性'be'

[英]mocha: Cannot read property 'be' of undefined

I'm writing unit test for my project. 我正在为我的项目编写单元测试。 But I always meet this problem 但我总是遇到这个问题

Cannot read property 'be' of undefined. 无法读取未定义的属性'be'。

I have a test suite called model-xxx, and I wanna try each method in this model. 我有一个名为model-xxx的测试套件,我想尝试这个模型中的每个方法。 So each method I write a sub test suite in model-xxx. 所以每个方法我都在model-xxx中编写一个子测试套件。 like this: 像这样:

enter image description here 在此输入图像描述

And each method is related with mongoose, so I hope these sub suite will be async. 并且每个方法都与mongoose有关,所以我希望这些子套件是异步的。 so each method I write done() in before and after and it 所以每个方法我写的done()beforeafterit

but none of these suite passed. 但这些套房都没有通过。 error like this: 像这样的错误:

enter image description here 在此输入图像描述

and like this: 和这样:

Cannot read property 'not' of undefined.

why this occurs? 为什么会这样? does this mean something wrong with my should.js ? 这对我的should.js什么不对吗? but it doesn't make sense 但它没有意义

hope for solutions. 希望有解决方案。

Chai's should is a function that needs to be called before you can use should-style assertions: Chai should是一个需要调用的函数 ,然后才能使用should-style断言:

var should = require('chai').should();

See the documentation . 请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM