为什么rake jasmine通过但是rake jasmine:ci因TypeError失败:undefined不是函数?

时间:2017-05-05 13:52:02

标签: javascript jasmine rake

使用rake jasmine,我的所有测试都会在浏览器中传递。

使用rake jasmine,2个规格失败:

TypeError: undefined is not a function (evaluating 'expect(player).not.toBePlaying(song)') in http://localhost:36091/__spec__/PlayerSpec.js (line 28)

我已将spec/javascripts/support/jasmine.yml文件配置为

src_files:
  - src/Player.js
  - src/Song.js
spec_files:
  - '**/*[sS]pec.js'
src_dir:
spec_dir: spec

src/Song.js有:

function Song() {
...

为什么rake jasmine:ci失败了这两个例子?

第一个失败的代码是:

it("should be able to play a Song", function() {
  player.play(song);
  expect(player.currentlyPlayingSong).toEqual(song);

  //demonstrates use of custom matcher
  expect(player).toBePlaying(song);  # <-- error here
});
似乎已加载

Song.js,因为如果删除它,则所有5个示例都会失败。

1 个答案:

答案 0 :(得分:0)

我需要自定义匹配器toBePlaying

我能够通过在spec/javascripts/support/jasmine.yml文件中更改此内容来获取所有规范:

src_files:
  - src/Player.js
  - src/Song.js
  - spec/SpecHelper.js   # <--- Added to include the custom helper 'toBePlaying'

我曾尝试将其添加到spec_files部分,但需要列在src_files

相关问题