简体   繁体   English

在Karma测试中,未定义ReferenceError:describe

[英]In Karma Testing, ReferenceError: describe is not defined

I was about to do unit test in my project. 我打算在我的项目中进行单元测试。 What I wrote was just a simple test code. 我写的只是一个简单的测试代码。 However, there came out weird message : ReferenceError : describe is not defined. 但是,出现了奇怪的消息:ReferenceError:描述未定义。

How can I get over this ? 我该如何克服呢?

This is my code : 这是我的代码:

'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);
        });
    });
}());

You need to load the jasmine reference first. 您需要先加载茉莉花参考。

I've added a small sample config for you. 我为您添加了一个小示例配置。

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
});
 };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 笑话:ReferenceError:描述未定义 - Jest : ReferenceError: describe is not defined 使用Jasmine和Karma测试离子-未捕获的ReferenceError:角度未定义 - Testing Ionic with Jasmine and Karma - Uncaught ReferenceError: angular is not defined Webpack和Karma测试:未捕获的ReferenceError:未使用定义jQuery - Webpack and Karma Testing: Uncaught ReferenceError: jQuery is not defined using Karma:未定义的ReferenceError $未定义 - Karma: uncaught ReferenceError $ is not defined 未捕获ReferenceError:describe未定义cors - Uncaught ReferenceError: describe is not defined cors 单元测试AngularJS:未捕获错误:[$ injector:nomod]模块不可用! 和ReferenceError:运行Karma时未定义模块 - Unit-Testing AngularJS: Uncaught Error: [$injector:nomod] Module is not available! and ReferenceError: module is not defined when run Karma ReferenceError:未定义浏览器 - 使用Karma和Jasmine - ReferenceError: browser is not defined - Using Karma and Jasmine 业力中的茉莉花测试:未捕获的ReferenceError:未定义require - jasmine tests in karma: Uncaught ReferenceError: require is not defined 使用Karma进行角度测试:“模块未定义” - Angular testing with Karma: “module is not defined” Redux测试 - ReferenceError:未定义localStorage - Redux Testing - ReferenceError: localStorage is not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM