2012-09-13 3 views
0

나는 JavaScript의 초보자입니다. Jasmine의 테스트를 통해 Class에 대해 배우고 있습니다. 나는 시험을 치려고했지만, 노력에도 불구하고 재스민은 녹색으로 보이지 않습니다.간단한 클래스 테스트가 통과하지 않습니다

// Generated by CoffeeScript 1.3.3 
var Animal; 

Animal = (function() { 

    function Animal() {} 

    Animal.prototype.walk = function() { 
    return 'tok tok...'; 
    }; 

    return Animal; 

})(); 

그리고 테스트 코드는 다음과 같습니다 :

내 코드는 다음과 같습니다

// Generated by CoffeeScript 1.3.3 

describe("Animal", function() { 
    var animal; 
    animal = new Animal; 
    it("shold walk", function() { 
    expect(animal.walk).toBe('tok tok...'); 
    }); 
}); 

그리고 재스민의 메시지는 다음과 같습니다 :

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) 

나는 지쳐입니다. 친절함에 감사드립니다 ...

답변

4

함수를 실행해야 함수의 결과를 함수 자체가 아닌 문자열로 비교해야합니다.

expect(animal.walk()).toBe('tok tok...'); 
관련 문제