2016-04-08 48 views
0

目前我已經在和AnotherService測試套件在同一文件,即service.test.js測試失敗時分成不同的文件

當我按原樣運行npm test時,ServiceAnotherService的測試運行良好並通過。

但是,如果我將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

不幸的是我不知道的摩卡是如何配置的,但這種類型的行爲通常是配置問題。 – AdamCooper86

+0

我沒有摩卡配置文件,因此使用默認值 – bobbyrne01

+0

是否有錯誤消息? – vintem

回答

0

去與簡單..

"scripts": { 
    "start": "node app.js", 
    "test": "mocha ./service.test.js && mocha ./anotherservice.test.js && jshint .", 
0

您可以編輯您的package.json文件,並運行此:

"scripts": { 
"start": "node app.js", 
"test": "mocha && jshint ./*.test.js" //this will execute all the files with suffix test.js