在业力测试中,没有定义ReferenceError:description
In Karma Testing, ReferenceError: describe is not defined
我正要在我的项目中进行单元测试。我写的只是一个简单的测试代码。然而,出现了一条奇怪的消息:ReferenceError:未定义描述。
我该怎么克服?
这是我的代码:
'use strict';
(function() {
//Cal test Controller Spec
describe('Cal test Controller Tests',function(){
//Initialize global variables
var CalTestController,
scope;
//Then we can start by loading the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
//The injector ignores leading and trailing underscores here(i.e._$httpBackend_).
//This allows us to inject a service but then attach to it to a variable.
//with the same name as the service.
beforeEach(inject(function($controller,$rootScope){
//Set a new global scope
scope=$rootScope.$new();
//Initialize the Cal test controller.
CalTestController = $controller('CalController',{
$scope:scope
});
}));
var a;
it('contains spec with an expectation',inject(function(){
a = true;
expect(a).toBe(true);
}));
});
describe("The 'toBe' matcher compares with===",function(){
it("and has a positive case",function(){
expect(true).toBe(true);
});
it("and can have a negative case",function(){
expect(false).not.toBe(true);
});
});
}());
您需要首先加载jasmine引用。
我为您添加了一个小的配置示例。
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', 'requirejs'],
// list of files / patterns to load in the browser
files: [
{pattern: 'src/test/js/extlib/jquery.191.js', included: true},
**LOAD MORE**
{pattern: 'src/main/js/src/**/*.js', included: false},
{pattern: 'src/test/js/spec/src/**/*.spec.js', included: false}
],
// 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: ['Firefox', 'Chrome', 'IE'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
相关文章:
- 用嵌套函数和默认函数定义函数
- Dojo不解析自定义小部件的模板html中的小部件声明性
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 控制台返回var不是't定义,但它是
- 在自定义mean.io包中使用angular-chart.js作为依赖项
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- jQuery自定义验证比较多个输入的序列
- 查看JS对象的所有键,甚至是getter定义的键
- fetch() 函数未在 Ubuntu Chromium 浏览器上定义
- $window.ga在AngularJS事件中未定义
- 如何在JQuery函数中定义一个值,然后调用另一个函数并使用该值
- 是否有任何方法可以使用jQuery替换在数组中定义值的文本
- 未捕获的TypeError无法读取未定义的属性socialsharing
- WebDriverException:tinyMCE未在selenium Web driver java中定义
- 从HTTPGET返回一个自定义对象列表,以便在Angular 2应用程序中使用
- 定义完全独立的样式信息
- 如何在选项卡上定义属性'的主窗口对象
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的