【问题标题】:Simple Class test does not pass简单类测试未通过
【发布时间】:2012-09-13 10:55:58
【问题描述】:

我是 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...');
  });
});

Jasmine 的消息如下:

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)

我已经筋疲力尽了。谢谢你的好意...

【问题讨论】:

    标签: javascript coffeescript jasmine


    【解决方案1】:

    您需要执行函数,将函数的结果与字符串进行比较,而不是函数本身。

    expect(animal.walk()).toBe('tok tok...');
    

    【讨论】:

      猜你喜欢
      • 2019-11-10
      • 1970-01-01
      • 1970-01-01
      • 2016-08-12
      • 1970-01-01
      • 2014-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多