javascript - 使用 jasmine-node 在 Frisby JS 中忽略 child 测试

标签 javascript meteor jasmine jasmine-node frisby.js

我使用 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) 它未通过测试 行。 如果我删除这一行,测试将运行并且 jasmine 验证它是否正确。

您知道如何避免忽略 (2) 和 (3) 测试吗?

最佳答案

最后,我找到了解决方案。 这是因为我忘记像下面的代码那样返回所有飞盘 Action (第一个除外):

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 运算符。 希望对您有所帮助!

关于javascript - 使用 jasmine-node 在 Frisby JS 中忽略 child 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46269627/

相关文章:

javascript - 选项 不允许的方法。获取作品但不发布

javascript - 使用 JavaScript/jQuery 在重定向上发送 POST 数据?

meteor - 在 Meteor 中执行 DOM 操作的正确方法是什么?

javascript - Meteor 发送给活跃用户

javascript - Jasmine 不适用于文档点击上的链接指令

javascript - jQuery 更新不起作用,但 javascript 可以

javascript - jquery 如何给帖子添加评论

javascript - Meteor.publish 回调需要在 Fiber 中包装

javascript - 嵌套 AngularJS promise 在单元测试中不起作用

angularjs - 如何使用karma + Jasmine加载外部Json文件以进行angularJS测试?/