gpt4 book ai didi

unit-testing - "framework:requirejs"没有提供者! (解决 : framework:requirejs)

转载 作者:行者123 更新时间:2023-12-04 18:37:57 31 4
gpt4 key购买 nike

我已经下载 this karma-jasmine sample code ,我用谷歌搜索了很多,似乎它必须工作。

但每当我跑

   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

我已经做对了一切,但仍然没有运气,而且 SO 中有一些问题似乎与我的相同,我已经尝试了所有答案,但仍然没有运气;

任何帮助,将不胜感激

谢谢

最佳答案

您需要 requirejs & karma-requirejs :

npm install requirejs --save-dev
npm install karma-requirejs --save-dev

之后,请确保按照“ Run Karma with Require.js”中的描述配置 Karma。

最小工作示例(由 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
})
};

test-main.js
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
});

关于unit-testing - "framework:requirejs"没有提供者! (解决 : framework:requirejs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31258802/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com