找不到变量:spyOn

时间:2016-05-18 16:20:23

标签: javascript angularjs jasmine

我在茉莉花测试用例承诺响应处理部分

上遇到问题

这是我在(wepaCore.api)服务中的休息服务处理方法:

this.auth = function (email, password) {
if (!password || !email) {
  Analytics.trackException(errorMessages.INVALID_EMAIL_PASS, true)

  return $q.reject({
    error: errorMessages.INVALID_INPUT,
    errorDescription: errorMessages.INVALID_EMAIL_PASS
  })
}

return this.makeApiCall('/oauth/token', {
  grant_type: 'password',
  username: email,
  password: password
}, {
  data: {},
  authHeader: 'Basic ' + constants.BASIC_AUTH_TOKEN
})
  .then(function (data) {
    accessToken = data['access_token']
    return accessToken
  }, function (data) {
    return $q.reject(data)
  })

}

我的测试用例方法:

    describe('wepaCore.api', function () {
      var login, $q, deferred

      // load the modules
      beforeEach(module('wepaCore'))

      // inject the services
      beforeEach(inject(function ($injector) {
        $q = $injector.get('$q')
        deferred = $q.defer()
        login = $injector.get('wepaCore.api')
        // Use a Jasmine Spy to return the deferred promise
        spyOn(login, 'auth').and.returnValue(deferred.promise)
      }))
})

获取“无法找到变量:spyOn”错误

PhantomJS 2.1.1 (Windows 8 0.0.0) wepaCore.api "before each" hook: workFn FAILED
    Can't find variable: spyOn
    e:/wepa/wepa-angular-core-dev/test/unit/apiSpec.js:24:10
    invoke@e:/wepa/wepa-angular-core-dev/bower/angular/angular.js:4665:24
    workFn@e:/wepa/wepa-angular-core-dev/bower/angular-mocks/angular-mocks.js:2965:26
    inject@e:/wepa/wepa-angular-core-dev/bower/angular-mocks/angular-mocks.js:2931:28
    e:/wepa/wepa-angular-core-dev/test/unit/apiSpec.js:19:20
    global code@e:/wepa/wepa-angular-core-dev/test/unit/apiSpec.js:12:9

你能帮忙解决这个错误吗?

0 个答案:

没有答案