Unit testing “无供应商”;框架:requirejs";!(解析:框架:requirejs)

Unit testing “无供应商”;框架:requirejs";!(解析:框架:requirejs),unit-testing,requirejs,karma-jasmine,Unit Testing,Requirejs,Karma Jasmine,我已经下载了,我在谷歌上搜索了很多,看来它一定能用 但当我跑的时候 karma start karma.conf.js 它给了我这个错误: /Users/xe4me/www/html/apache/requirejs- karma/node_modules/karma/node_modules/di/lib/injector.js:9 throw error('No provider for "' + name + '"!'); ^ Error: No p

我已经下载了,我在谷歌上搜索了很多,看来它一定能用

但当我跑的时候

   karma start karma.conf.js
它给了我这个错误:

 /Users/xe4me/www/html/apache/requirejs-     karma/node_modules/karma/node_modules/di/lib/injector.js:9
  throw error('No provider for "' + name + '"!');
        ^
 Error: No provider for "framework:jasmine"! (Resolving: framework:jasmine)
at error (/Users/xe4me/www/html/apache/requirejs-karma/node_modules/karma/node_modules/di/lib/injector.js:22:68)
at Object.parent.get (/Users/xe4me/www/html/apache/requirejs-karma/node_modules/karma/node_modules/di/lib/injector.js:9:13)
at get (/Users/xe4me/www/html/apache/requirejs-karma/node_modules/karma/node_modules/di/lib/injector.js:54:19)
at /Users/xe4me/www/html/apache/requirejs-karma/node_modules/karma/lib/server.js:29:14
at Array.forEach (native)
at start (/Users/xe4me/www/html/apache/requirejs-karma/node_modules/karma/lib/server.js:28:21)
at invoke (/Users/xe4me/www/html/apache/requirejs-karma/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at Object.exports.start (/Users/xe4me/www/html/apache/requirejs-karma/node_modules/karma/lib/server.js:307:12)
at Object.exports.run (/Users/xe4me/www/html/apache/requirejs-karma/node_modules/karma/lib/cli.js:220:27)
at requireCliAndRun (/usr/local/lib/node_modules/karma-cli/bin/karma:44:16)
我也采用了以下方法,但运气不佳:

 npm install karma-requirejs --save-dev
我做的每件事都是对的,但是仍然没有运气,而且里面也有一些问题,看起来和我的一样,我尝试了所有的答案,但是仍然没有运气

任何帮助都将不胜感激


谢谢

您需要
requirejs
karma requirejs

npm install requirejs --save-dev
npm install karma-requirejs --save-dev
之后,确保按照“”中所述配置业力

最小工作示例(由
karma init
生成)

karma.conf.js

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', 'requirejs'],
    files: [
      {pattern: 'dest/main/**/*.js', included: false},
      {pattern: 'test/**/*Spec.js', included: false},
      'test-main.js'
    ],
    exclude: [],
    preprocessors: {},
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: false,
    browsers: ['Chrome'],
    singleRun: false,
    concurrency: Infinity
  })
};
var allTestFiles = [];
var TEST_REGEXP = /(spec|test)\.js$/i;

// Get a list of all the test files to include
Object.keys(window.__karma__.files).forEach(function(file) {
  if (TEST_REGEXP.test(file)) {
    // Normalize paths to RequireJS module names.
    // If you require sub-dependencies of test files to be loaded as-is (requiring file extension)
    // then do not normalize the paths
    var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, '');
    allTestFiles.push(normalizedTestModule);
  }
});

require.config({
  // Karma serves files under /base, which is the basePath from your config file
  baseUrl: '/base',

  // dynamically load all test files
  deps: allTestFiles,

  // we have to kickoff jasmine, as it is asynchronous
  callback: window.__karma__.start
});
测试main.js

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', 'requirejs'],
    files: [
      {pattern: 'dest/main/**/*.js', included: false},
      {pattern: 'test/**/*Spec.js', included: false},
      'test-main.js'
    ],
    exclude: [],
    preprocessors: {},
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: false,
    browsers: ['Chrome'],
    singleRun: false,
    concurrency: Infinity
  })
};
var allTestFiles = [];
var TEST_REGEXP = /(spec|test)\.js$/i;

// Get a list of all the test files to include
Object.keys(window.__karma__.files).forEach(function(file) {
  if (TEST_REGEXP.test(file)) {
    // Normalize paths to RequireJS module names.
    // If you require sub-dependencies of test files to be loaded as-is (requiring file extension)
    // then do not normalize the paths
    var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, '');
    allTestFiles.push(normalizedTestModule);
  }
});

require.config({
  // Karma serves files under /base, which is the basePath from your config file
  baseUrl: '/base',

  // dynamically load all test files
  deps: allTestFiles,

  // we have to kickoff jasmine, as it is asynchronous
  callback: window.__karma__.start
});
尝试将“karma requirejs”添加到karma.conf.js中的插件数组中

...

plugins: [             
            'karma-jasmine',                      
            'karma-chrome-launcher',                
            'karma-jasmine-html-reporter',
            'karma-webpack',
            'karma-requirejs'
        ],


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

...

您必须
npm安装karma jasmine
。但它仍然不起作用。。任何关于Karma最新更新的更新谢谢,帮助信息应该说
你忘记安装了吗?npm安装requirejs karma requirejs