简体   繁体   English

因果报应找不到我的茉莉花测试,TypeError

[英]Karma not finding my jasmine test, TypeError

When trying to run my jasmine test, which is testing my angular customer directive "book directive" using test-runner karma i'm getting the following output errors: (I'm getting various TypeErrors from each script file, not even finding my test let alone showing a failing test)) 尝试运行我的茉莉花测试(使用测试运行程序业力测试我的有角度的客户指令“ book指令”)时,我收到以下输出错误:(我从每个脚本文件中得到各种TypeError,甚至没有找到我的测试更不用说显示失败的测试了))

Karma Output 业力输出

------ Discover test started ------
Error: TypeError: undefined is not an object (evaluating 'angular.module')
in file:///c:/users/ray/documents/visual%20studio%202013/projects/requirejsdemo/requirejsdemo/scripts/angular-route.js (line 24)
While Running:c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-route.js

Error: TypeError: undefined is not an object (evaluating 'angular.$$minErr')
in file:///c:/users/ray/documents/visual%20studio%202013/projects/requirejsdemo/requirejsdemo/scripts/angular-sanitize.js (line 8)
While Running:c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-sanitize.js

Error: ReferenceError: Can't find variable: define
at global code in file:///c:/users/ray/documents/visual%20studio%202013/projects/requirejsdemo/requirejsdemo/tests/newfeaturetests/directivetest.js (line 3)
While Running:c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\tests\newfeaturetests\directivetest.js

Error: TypeError: Attempted to assign to readonly property.
in file:///c:/users/ray/documents/visual%20studio%202013/projects/requirejsdemo/requirejsdemo/scripts/angular-mocks.js (line 17)
While Running:c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-mocks.js

[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-mocks.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-route.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-sanitize.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-scenario.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\jasmine.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\tests\newfeaturetests\directivetest.js
========== Discover test finished: 0 found (0:00:17.4009953) ==========

karma.conf file karma.conf文件

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: [
        "Scripts/angular.js",
           { pattern: "Scripts/require.js", included: false },
              { pattern: "Scripts/jasmine.js", included: false },
                 { pattern: "Scripts/angularAMD.js", included: false },
                    { pattern: "Scripts/jquery-1.8.2.js", included: false },
        { pattern: "Js/**/*.js", included: false },
        { pattern: "tests/NewFeatureTests/*.js", included: false },
        { pattern: "Js/NewFeature/*.html", include: false },

        "tests/test-main.js"
    ],


    // list of files to exclude
    exclude: [
        "Js/main.js"
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
        "Js/**.*.html": ["ng-html2js"]
    },


    // 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,

    plugins: [
        'karma-ng-html2js-preprocessor'
    ],

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

Jasmine Test 茉莉花测试

'use strict'

define(['angular', 'jquery',], function (angular) {

    describe('bookDirective', function () {
      var el;

        // Load the myApp module, which contains the directive
        beforeEach(module('testModule'));
        beforeEach(module('Js/NewFeature/Book.html'));

        // Store references to $rootScope and $compile
        // so they are available to all tests in this describe block
        beforeEach(inject(function ($compile, $rootScope) {
            // The injector unwraps the underscores (_) from around the parameter names when matching
            scope = _$rootScope_;

            scope.color = "red";
            scope.title = "ghost";
            //create and compile directive
            el = angular.element("<book title='Ghost' color='red'></book>");

            // compile the dom node and apply the scope, this will return a getter function
            $compile(el)(scope);

            scope.$digest(); // update the html
        }));

        it('background colour of book should be red', function () {
            // check if background color is red
            expect(el.css('background-color').toEqual('red'));
        });

    });

});

How do I get my tests to run? 我如何运行测试?

your base path is basePath: '../', . 您的基本路径是basePath:'../',。 So, files array should be 因此,文件数组应为

files: [
        "../scripts/angular.js",
       "../scripts/angular-route.js",
       "../scripts/angular-mocks.js",
       "../scripts/angular-sanitize.js",
       "../scripts/angular-scenario.js",
       "../scripts/jasmine.js",
       "../tests/newfeaturetests/directivetest.js",
       "../tests/test-main.js"
    ]

Please check base path. 请检查基本路径。

Please also check your index.html file for all script JS that you included and list it in files Array.Otherwise it will lead error if one of those script will dependency for other. 请同时检查index.html文件中包含的所有脚本JS并将其列出在Array 文件中,否则如果其中一个脚本依赖于其他脚本,则会导致错误。

Also in your jasmine test beforeEach(module('Js/NewFeature/Book.html')); 同样在您的茉莉花测试中beforeEach(module('Js / NewFeature / Book.html'));

this is wrong.This is not module name registered with angular app.Please check it.remove it. 这是错误的。这不是在角度应用程序中注册的模块名称。请检查并删除。

Also please refer directive testing for more. 另请参阅指令测试以获取更多信息。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM