jasmine-node icon indicating copy to clipboard operation
jasmine-node copied to clipboard

toThrowError fails the spec when string is passed

Open deeprnd opened this issue 11 years ago • 1 comments

Trying to test the examples of Jasmine fails the last spec "Player #resume should throw an exception if song is already playing", when trying to catch the error. Throwing class (Player.js): Player.prototype.resume = function() { if (this.isPlaying) { throw new Error("song is already playing"); }

Catching spec: describe("#resume", function() { it("should throw an exception if song is already playing", function() { player.play(song);

  expect(function() {
    player.resume();
  }).toThrowError("song is already playing");
});

});

Changing "toThrowError" to "toThrow" fixes the problem: describe("#resume", function() { it("should throw an exception if song is already playing", function() { player.play(song);

  expect(function() {
    player.resume();
  }).toThrow(new Error("song is already playing"));
});

});

deeprnd avatar Aug 19 '14 09:08 deeprnd

It's because jasmine-node currently uses Jasmine v1.3.1 and toThrowError isn't available until v2.0.0

AustP avatar Jan 16 '15 18:01 AustP