0

I am new to using Jasmine and BDD testing and I am trying to test if a simple page exists.

I have the following code:

describe("when server is running",function () {
  it("should serve an index page", function(){
    expect(server.app).toBeDefined();
    request.get('http://localhost:3000/', function(error, response, body){
      expect(response.statusCode).toBeEqual(200);
      done();
    });
    expect(server.app).toBeDefined();
  });
});

When the tests are run I get:

Finished in 0.027 seconds
1 test, 2 assertions, 0 failures, 0 skipped

There are obviously 3 assertions and it's the middle one, within the function() call that is not performed (I added the third repetitive one just for checking and commented out each one individually).

I came across the guide at https://semaphoreci.com/community/tutorials/getting-started-with-node-js-and-jasmine and made not of the addition of the done() callback but still no joy.

Is this something wrong with the test, the request or the jasmine-node setup I have.

I'm running this on Ubuntu 14.04.

Thanks.

James Bubb
  • 3,023
  • 1
  • 12
  • 12
  • Try adding done as a parameter to the it() callback function, so `it('name', function (done) {} )`... Also, you should not have any assertions after a done has been called like you have in this case. Put your final assertion (if you need it) immediately before calling done. – Shakespeare Apr 12 '16 at 20:46
  • Thanks, I did see the 'done' parameter in another example but it was not present in the tutorial I mentioned so didn't include it. I tried with the done parameter and removed the two .toBeDefined assertions and now the result from running the tests is nothing (no output). Edit - I lie it is in that tutorial I just didn't see it! – James Bubb Apr 12 '16 at 21:16
  • OK, so figured it out. The done parameter is required however it was an error with the matcher I had used. There is no .toBeEqual(). Changing this to .toBe() or .toEqual() sorted the problem. Thanks @OwenAyres for the help. – James Bubb Apr 12 '16 at 21:21
  • Ahh, can't believe I missed that. Glad you solved it on your own though! – Shakespeare Apr 13 '16 at 07:36

0 Answers0