小编did*_*man的帖子

使用Jasmine以uibModal和lodash作为依赖项来测试服务

这是我第一次使用Jasmine,我已经测试了我的第一个工厂没有问题.

但是现在,我想测试这个服务:

angular.module('Questions', [])
.service('QuestionsService', function($uibModal, $log, _) { 
  ... 
}
Run Code Online (Sandbox Code Playgroud)

$ uibModal来自UI Bootstrap(见这里),_是Lodash.

到目前为止我的茉莉花测试是:

describe('Service: QuestionsService', function() {

    var QuestionsService;

    beforeEach(inject(function(_QuestionsService_) {
      QuestionsService = _QuestionsService_;
    }));

    ...
}
Run Code Online (Sandbox Code Playgroud)

当我尝试它(咕噜声测试)时,我收到以下错误:

错误:[$ injector:unpr]未知提供者:$ uibModalProvider < - $ uibModal < - QuestionsService

在某些时候我也有:

错误:[$ injector:unpr]未知提供者:_Provider < - _ < - QuestionsService

如果它可以提供帮助,我的Karma conf是:

module.exports = function(config) {
  'use strict';
  config.set({
    autoWatch: true,
    basePath: '../',

    frameworks: [
      "jasmine"
    ],

    // list of files / patterns to load in the browser
    files: …
Run Code Online (Sandbox Code Playgroud)

javascript jasmine angularjs angular-ui-bootstrap lodash

6
推荐指数
1
解决办法
2819
查看次数