当分离到不同的文件中时,测试失败
Test fails when separated into different files
目前,我在同一个文件(即service.test.js
)中有Service
和AnotherService
的测试套件。
当我按原样运行npm test
时,Service
和AnotherService
的测试运行良好并通过
但是,如果我将AnotherService
的测试套件移动到anotherservice.test.js
,则service.test.js
的测试将失败,这很奇怪。
有人知道为什么吗?
package.json
..中的片段。。
"scripts": {
"start": "node app.js",
"test": "mocha && jshint .",
service.test.js
..内的代码。。
// this works fine
describe('Service', function() {
describe('delete()', function() {
it('should respond with a 401 as we are supplying user and no password', function(done) {
request(app).delete('/item/0033cb8e-86a4-4dc1-9c2e-a07ca226d43f/')
.set('x-header-db', 'db')
.set('x-header-db-host', 'host')
.set('x-header-db-credname', 'uname')
.set('x-header-db-credpass', '')
.expect(401)
.end(done);
});
});
});
// this works here, but if moved to another file the test above fails
describe('AnotherService', function() {
describe('delete()', function() {
it('should respond with a 401 as we are supplying user and no password', function(done) {
request(app).delete('/item/0033cb8e-86a4-4dc1-9c2e-a07ca226d43f/')
.set('x-header-db', 'db')
.set('x-header-db-host', 'host')
.set('x-header-db-credname', 'uname')
.set('x-header-db-credpass', '')
.expect(401)
.end(done);
});
});
});
列出的目录片段
├── package.json
├── README.md
├── src
│ ├── serivce.js
│ └── anotherservice.js
└── test
├── service.test.js
└── anotherservice.test.js
您可以编辑您的package.json文件并运行以下命令:
"scripts": {
"start": "node app.js",
"test": "mocha && jshint ./*.test.js" //this will execute all the files with suffix test.js
只使用。。
"scripts": {
"start": "node app.js",
"test": "mocha ./service.test.js && mocha ./anotherservice.test.js && jshint .",
相关文章:
- ChaiJS:无法导致测试失败
- 当我的单元测试失败时,回调被调用了两次
- 预期[false]为false量角器e2e测试失败
- 为什么在我的单元测试中instanceOf的测试失败
- yeoman generator聚合物的web组件测试失败
- 当Firefox尝试登录时,Selenium测试失败
- 量角器中的AngularJS E2E测试失败
- 用摩卡测试失败的承诺'内置的promise支持
- 这个单元测试失败的原因是什么
- 当分离到不同的文件中时,测试失败
- travis测试失败,通过本地测试
- 字符串测试失败
- Javascript单元测试依赖关系-当依赖对象发生变化时,如何使测试失败
- 如何在捕获Promise时使Node单元测试失败
- AngularJs的单元测试失败是因为Karma没有'无法识别$scope$控制器中的侦听器
- 有没有办法在node.js中的异常或测试失败时启动调试器
- Capybara JS 测试失败了 page.all
- 现代化测试失败后仍应用函数
- 角度咆哮 V2 - 单元测试失败
- 为什么这个 QUnit 测试失败