我使用Frisy和jasmine-node来测试Meteor API .
我想在聊天应用程序中测试删除讨论 . 为此,我需要在聊天中创建一个新的讨论,并在讨论中添加一条消息 .
我注意到如果我把它放在第二个.then()方法之后我的测试失败了 . 它在第三个.then()之后也失败了 . 但是,它在第一个.then()方法之后正常工作 .
显式失败测试的示例代码 expect(false).toBe(true); :
var frisby = require('frisby');
describe("chat update", function() {
it("message added", function(done) {
frisby.post('http://localhost:3000/api/chat', {
name: "remove"
})
.then(function (res) {
let id = res._body.id;
expect(false).toBe(true); // (1) it fails the test
frisby.post('http://localhost:3000/api/chat/'+id+'/addmessage',
{
auteur: "Samuel",
message: "My message"
}
)
.then(function (res) {
expect(false).toBe(true); // (2) Without (1) it's ignored by frisby
frisby.post('http://localhost:3000/api/chat/remove',
{id: id}
)
.then(function (res) {
expect(false).toBe(true); // (3) Without (1) it's ignored by frisby
})
});
})
.done(done);
})
});
如果我运行测试,由于 expect(false).toBe(true); // (1) it fails the test 行,它将失败 . 如果我删除此行,测试将运行并且jasmine将其正确有效 .
你知道一种不忽视(2)和(3)测试的方法吗?
1 回答
最后,我找到了解决方案 . 这是因为我忘了 return all frisby action (第一个除外),如下面的代码所示:
您可能会在 frisby.post() 之前注意到 return 运算符 . 我希望它会有所帮助!