Jasmine 测试没有看到 AngularJS 模块 [英] Jasmine test does not see AngularJS module

查看:20
本文介绍了Jasmine 测试没有看到 AngularJS 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to unit test an Angular service with a Jasmine spec file. This requires that a module be loaded. Here is a simple spec designed in an attempt to simply load the Angular module:

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

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

When I run Jasmine, this results in the following error

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 文件包含

The jasmine.yml file contains

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
  • 茉莉花核 1.2.0
  • jasmine-headless-webkit 0.8.4
  • AngularJS 1.0.2

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

推荐答案

确保包含 http://code.angularjs.org/1.1.0/angular-mocks.js 用于像 module 这样的 angular-jasmine-helper 函数.

Make sure you include http://code.angularjs.org/1.1.0/angular-mocks.js for the angular-jasmine-helper functions like module.

这篇关于Jasmine 测试没有看到 AngularJS 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆