2016-04-08 11 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