一尘不染

Jasmine测试看不到AngularJS模块

angularjs

我正在尝试使用Jasmine规格文件对Angular服务进行单元测试。这需要加载模块。这是一个简单的规范,旨在简单地加载Angular模块:

describe('Submission services', function () {
  it('Finds angular', function () {
    module('submissionServices');
  });
});

当我运行Jasmine时,这将导致以下错误

Running Jasmine specs...
FAIL: 1 test, 1 failure, 0.004 secs.

Submission services Finds angular. (/Users/XXX/Projects/globe_town/spec/javascripts/SubmissionsSpec.js:3)
ReferenceError: Can't find variable: module

Test ordering seed: --seed 1826
rake aborted!
Jasmine::Headless::TestFailure

jasmine.yml文件包含

src_files:
  - public/javascripts/jquery.js
  - spec/javascripts/lib/angular/angular.js
  - spec/javascripts/lib/angular/angular-resource.js
  - app/assets/javascripts/services/submissions.js

stylesheets:
  - stylesheets/**/*.css

helpers:
  - helpers/**/*.js

spec_files:
  - '**/*[sS]pec.js'

src_dir:

spec_dir: spec/javascripts

该软件的版本为:

  • Rails 3.2.7
  • jasmine-core 1.2.0
  • jasmine-headless-webkit 0.8.4
  • AngularJS 1.0.2

我需要做些什么才能使Jasmine找到Angular?


阅读 178

收藏
2020-07-04

共1个答案

一尘不染

确保为像这样的angular-jasmine-helper函数添加了http://code.angularjs.org/1.1.0/angular-
mocks.jsmodule

2020-07-04