【问题标题】:configuration of karma/jasmine to test angularjs throws: No provider for "framework:jasmine"!配置业力/茉莉花来测试 angularjs 抛出:“框架:茉莉花”没有提供者!
【发布时间】:2015-06-15 08:39:18
【问题描述】:

您好,我正在尝试使用 karma 和 jasmine 为 angularjs 实现单元测试。因此,我遵循了本教程: http://tech.pro/tutorial/1473/getting-started-with-angularjs-unit-testing

关于Running Your First测试,我因为一个错误而被吸引:

没有“framework:jasmine”的提供者!

我用谷歌搜索并尝试了建议的方法,例如再次安装 karma-jasmine 和 karma-chrome-launcher,但这些都不适合我。

我的 package.json 看起来像这样:

{
  "name": "projectName",
  "version": "1.0.0",
  "description": "a description",
  "dependencies": {
    "gulp": "^3.5.6",
    "gulp-sass": "^1.3.3",
    "gulp-concat": "^2.2.0",
    "gulp-minify-css": "^0.3.0",
    "gulp-rename": "^1.2.0"
  },
  "devDependencies": {
    "bower": "^1.3.3",
    "gulp-util": "^2.2.14",
    "jasmine-core": "^2.3.4",
    "karma": "^0.12.36",
    "karma-chrome-launcher": "^0.1.12",
    "karma-jasmine": "^0.3.5",
    "karma-safari-launcher": "^0.1.1",
    "shelljs": "^0.3.0"
  },
  "cordovaPlugins": [
    "org.apache.cordova.device",
    "org.apache.cordova.console",
    "com.ionic.keyboard"
  ],
  "cordovaPlatforms": [
    "android",
    "ios"
  ]
}

还有我的业力配置karma.conf.js:

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
      'test/*/Specs.js',
      'test/*'
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome', 'Safari'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  });
};

如果我运行karma start karma.conf.js,我总是会收到错误消息。我什至更改了这两个文件的权限,但没有任何效果。这里有什么问题?

【问题讨论】:

标签: angularjs unit-testing karma-jasmine


【解决方案1】:

原来我已经全局安装了 karma npm install -g karma 和本地安装了 karma-jasmine npm install karma-jasmine。我在全球范围内重新安装了 karma-jasmine,现在它可以工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    • 1970-01-01
    • 2023-03-27
    相关资源
    最近更新 更多