Reputation: 2783
I am newbie of JavaScript. I am learning about Class with testing by Jasmine. I tried to clear the test, but despite of my efforts, Jasmine does not show green.
My code is below:
// Generated by CoffeeScript 1.3.3
var Animal;
Animal = (function() {
function Animal() {}
Animal.prototype.walk = function() {
return 'tok tok...';
};
return Animal;
})();
And the test code is below:
// Generated by CoffeeScript 1.3.3
describe("Animal", function() {
var animal;
animal = new Animal;
it("shold walk", function() {
expect(animal.walk).toBe('tok tok...');
});
});
And the message from Jasmine is below:
Expected Function to be 'tok tok...'.
Error: Expected Function to be 'tok tok...'.
at new jasmine.ExpectationResult (http://localhost:8888/__JASMINE_ROOT__/jasmine.js:102:32)
at null.toBe (http://localhost:8888/__JASMINE_ROOT__/jasmine.js:1194:29)
at null.<anonymous> (http://localhost:8888/__spec__/AnimalSpec.js:8:25)
at jasmine.Block.execute (http://localhost:8888/__JASMINE_ROOT__/jasmine.js:1024:15)
at jasmine.Queue.next_ (http://localhost:8888/__JASMINE_ROOT__/jasmine.js:2025:31)
at goAgain (http://localhost:8888/__JASMINE_ROOT__/jasmine.js:2015:18)
I am exhausted. Thank you for your kindness...
Upvotes: 0
Views: 119
Reputation: 160833
You need to execute the function, compare the result of the function to a string, not the function itself.
expect(animal.walk()).toBe('tok tok...');
Upvotes: 4