目前,我在同一个文件中Service
和AnotherService
都有测试套件,service.test.js
。
当我按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
答案 0 :(得分:0)
您可以编辑package.json文件并运行:
"scripts": {
"start": "node app.js",
"test": "mocha && jshint ./*.test.js" //this will execute all the files with suffix test.js
答案 1 :(得分:0)
单纯地去......
"scripts": {
"start": "node app.js",
"test": "mocha ./service.test.js && mocha ./anotherservice.test.js && jshint .",