目前我已經在和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
不幸的是我不知道的摩卡是如何配置的,但這種類型的行爲通常是配置問題。 – AdamCooper86
我沒有摩卡配置文件,因此使用默認值 – bobbyrne01
是否有錯誤消息? – vintem