为什么我的Jasmine规格说'没有找到规格'

时间:2016-08-30 11:32:57

标签: javascript jasmine

我的Javascript功能是

function Investment (params) {
  var params = params || {};
  this.stock = params.stock;
  this.shares = params.shares
  this.cost = params.cost
};

我的规格是

describe("Investment", function() {

  beforeEach(function() {
    this.stock = new Stock();
    this.investment = new Investment({
      stock: this.stock,
      shares: 100
      cost: 2000
    });
  });

  it("should be a stock", function() {
    expect(this.investment.stock).toBe(this.stock);
  });

  it("should have the invested shares quantity", function() {
    expect(this.investment.shares).toEqual(100);
  });

  it("should have a cost", function() {
    expect(this.investment.cost).toEqual(2000);
  });
});

1 个答案:

答案 0 :(得分:3)

规范在其中一个参数之后缺少逗号,因此应该是:

beforeEach(function() {
  this.stock = new Stock();
  this.investment = new Investment({
    stock: this.stock,
    shares: 100,  <-- needs a comma here
    cost: 2000
  });
});