gpt4 book ai didi

asp.net-mvc - 使用 Jasmine 和 Karma 在 ASP.NET MVC 中对 JavaScript 进行单元测试

转载 作者:行者123 更新时间:2023-11-28 21:36:21 24 4
gpt4 key购买 nike

我正在编写一个示例 ASP .NET MVC 应用程序,它具有 karma 和 requirejs 来测试脚本。我看到以下错误 Uncaught (in promise) Error: No tests were run.

我在命令提示符中看到以下错误Chrome 77.0.3865 (Windows 10.0.0):执行 0 次,共 0 次错误(0.012 秒/0 秒)

包.json

{
"name": "karmawebapp",
"version": "1.0.0",
"description": "test application for karma tests",
"main": "index.js",
"scripts": {
"test": "karma start"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-preset-es2015": "^6.24.1",
"karma": "^4.3.0",
"karma-chrome-launcher": "^3.1.0",
"karma-qunit": "^4.0.0",
"karma-requirejs": "^1.1.0",
"protractor": "^5.4.2",
"qunit": "^2.9.3",
"requirejs": "^2.3.6"
}
}

我的 karma.conf.js

// Karma configuration
// Generated on Tue Oct 15 2019 13:51:47 GMT-0500 (Central Daylight Time)

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: ['requirejs', 'qunit'],


// list of files / patterns to load in the browser
files: [
'test-main.js',
{ pattern: './Scripts/tests/*.specs.js', included: false }
],


// list of files / patterns 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'],


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

// Concurrency level
// how many browser should be started simultaneous
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,

path: {
qunit: 'qunit',
jquery: 'jquery.3.3.1'
},

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

我的 test.specs.js

define(['qunit'], function (qunit) {

qunit.test("Second test", function (assert) {
assert.ok(true, "Passed!");
});
});

最佳答案

使用调试设置在浏览器上打开 devtools: http://karma-runner.github.io/4.0/intro/troubleshooting.html

关于asp.net-mvc - 使用 Jasmine 和 Karma 在 ASP.NET MVC 中对 JavaScript 进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58401245/

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