javascriptmeteorjasminejasmine-nodefrisby.js

ignored children tests in Frisby JS with jasmine-node


I use Frisy with jasmine-node to test an Meteor API.

I want to test the remove of a discussion in a chat App. For this, I need to create a new discussion in chat and add a message in the discussion.

I noticed that my test fail if I put it after the second .then() method. It fails also after the third .then(). However, it works correctly after the first .then() method.

An example code with explicit failed test 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);
  })
});

If I run the test, it will fail thanks to expect(false).toBe(true); // (1) it fails the test line. If I remove this line, the test will run and jasmine valid it as right.

Do you know a way to don't ignore the (2) and (3) tests ?


Solution

  • Finaly, I found the solution. It's because I forgot to return all frisby action (except the first one) like in the following code:

    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);
      })
    });
    

    You may notice the return operators before frisby.post(). I hope it will help !