5

每次尝试将 angularjs 加载到测试文件时,我都会收到脚本错误。

当我尝试将 angularjs 放入 requirejs 定义块时,出现错误。

因果报应:

    module.exports = function (config) {
    config.set({
    basePath: '',

    frameworks: ['jasmine', 'requirejs'],
        files: [
        {pattern: 'C:/workspaces/trunk/pearl/client/components/angular/angular.js', included: false},
        {pattern: '../components/angular-mocks/angular-mocks.js', included: false},
        {pattern: '**/*Spec.js', included: false},
            'test-main.js'
        ],

        reporters: ['progress'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_DEBUG,
        autoWatch: false,
        browsers: ['PhantomJS'],
        captureTimeout: 60000,
        singleRun: true
    });
};

测试配置:

var tests = [];
for (var file in window.__karma__.files) {
    if (window.__karma__.files.hasOwnProperty(file)) {
        if (/Spec\.js$/.test(file)) {
            tests.push(file);
        }
    }
}

requirejs.config({

    paths: {
        'angular': '../components/angular/angular',
        'angular-mocks': '../components/angular-mocks/angular-mocks'
    },

    shim: {
        'angular': {exports: 'angular'},
        'angular-mocks': {
            deps: ['angular']
        }
    },

    // ask Require.js to load these files (all our tests)
    deps: tests,

    // start test run, once Require.js is done
    callback: window.__karma__.start
});

测试文件:

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

    describe('example test', function () {
        it('should pass the test', function () {
            expect(true).toBe(true);
        })
    });

});

当我尝试运行它时,我收到以下错误消息:

PhantomJS 1.9.1 (Windows 7): Executed 0 of 0 SUCCESS (0 secs / 0 secs)
PhantomJS 1.9.1 (Windows 7) ERROR
Error: Script error for: angular
http://requirejs.org/docs/errors.html#scripterror
at C:/workspaces/trunk/pearl/client/node_modules/karma-requirejs/lib/require.js:138
PhantomJS 1.9.1 (Windows 7): Executed 0 of 0 ERROR (0.06 secs / 0 secs)

您可以在此处看到所有已加载的文件:

C:\workspaces\trunk\pearl\client\example>grunt test
Running "karma:unit" (karma) task
DEBUG [plugin]: Loading karma-* from C:\workspaces\trunk\pearl\client\node_modules
DEBUG [plugin]: Loading plugin C:\workspaces\trunk\pearl\client\node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin C:\workspaces\trunk\pearl\client\node_modules/karma-coffee-preprocessor.
DEBUG [plugin]: Loading plugin C:\workspaces\trunk\pearl\client\node_modules/karma-firefox-launcher.
DEBUG [plugin]: Loading plugin C:\workspaces\trunk\pearl\client\node_modules/karma-html2js-preprocessor.
DEBUG [plugin]: Loading plugin C:\workspaces\trunk\pearl\client\node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin C:\workspaces\trunk\pearl\client\node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin C:\workspaces\trunk\pearl\client\node_modules/karma-requirejs.
DEBUG [plugin]: Loading plugin C:\workspaces\trunk\pearl\client\node_modules/karma-script-launcher.
DEBUG [plugin]: Loading inlined plugin (defining ).
INFO [karma]: Karma v0.10.2 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
DEBUG [launcher]: Creating temp dir at C:\Users\nirk\AppData\Local\Temp\karma-30300678
DEBUG [launcher]: C:\Program Files (x86)\phantomjs\phantomjs.exe C:\Users\nirk\AppData\Local\Temp\karma-30300678/capture.js
DEBUG [watcher]: Resolved files:
        C:/workspaces/trunk/pearl/client/node_modules/karma-requirejs/lib/require.js
        C:/workspaces/trunk/pearl/client/node_modules/karma-requirejs/lib/adapter.js
        C:/workspaces/trunk/pearl/client/node_modules/karma-jasmine/lib/jasmine.js
        C:/workspaces/trunk/pearl/client/node_modules/karma-jasmine/lib/adapter.js
        C:/workspaces/trunk/pearl/client/components/angular/angular.js
        C:/workspaces/trunk/pearl/client/example/welcomeScreen/welcomScreenSpec.js
        C:/workspaces/trunk/pearl/client/example/test-main.js

为什么angularjs会显示错误?

4

0 回答 0