Javascript 使用jasmine节点忽略Frisby JS中的子测试
我使用Frisy和jasmine节点来测试Meteor API 我想测试在聊天应用程序中删除讨论。为此,我需要在chat中创建一个新的讨论,并在讨论中添加一条消息 我注意到如果我把它放在第二个.then()方法之后,测试就会失败。第三次之后也会失败。然后()。但是,在第一个.then()方法之后,它可以正常工作 带有显式失败测试的示例代码expect(false).toBe(true):Javascript 使用jasmine节点忽略Frisby JS中的子测试,javascript,meteor,jasmine,jasmine-node,frisby.js,Javascript,Meteor,Jasmine,Jasmine Node,Frisby.js,我使用Frisy和jasmine节点来测试Meteor API 我想测试在聊天应用程序中删除讨论。为此,我需要在chat中创建一个新的讨论,并在讨论中添加一条消息 我注意到如果我把它放在第二个.then()方法之后,测试就会失败。第三次之后也会失败。然后()。但是,在第一个.then()方法之后,它可以正常工作 带有显式失败测试的示例代码expect(false).toBe(true): var frisby = require('frisby'); describe("chat update"
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) 它未通过测试行。
如果我删除这一行,测试将运行,jasmine将正确地验证它
你知道不忽略(2)和(3)测试的方法吗?最后,我找到了解决方案。 这是因为我忘了返回所有飞盘动作(第一个动作除外),如以下代码所示:
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;
return frisby.post('http://localhost:3000/api/chat/'+id+'/addmessage',
{
auteur: "Samuel",
message: "My message"
}
)
.then(function (res) {
return frisby.post('http://localhost:3000/api/chat/remove',
{id: id}
)
.then(function (res) {
expect(false).toBe(true); // Will fail the test
})
});
})
.done(done);
})
});
您可能会注意到frisby.post()前面的return操作符。
我希望这会有帮助 你用的是旧版本的飞盘还是新版本的?我问,因为“旧”版本使用jasmine节点,而新版本使用Jest。我使用新版本。我找到了解决办法,并把它作为一个答案。我忘了返回接线员。谢谢