ReferenceError: Невозможно найти переменную: d3

0

Привет, все, что я пытаюсь выполнить тестирование jasmine/karma в приложении d3, однако я не могу пройти мимо этой ошибки: ReferenceError: Не могу найти переменную: d3...

at getSvg (C:/Users/test/Desktop/bob/angular-force-directed-graph/src/app/d3mapping.spec.js:9)
            at C:/Users/test/Desktop/bob/angular-force-directed-graph/src/app/d3mapping.spec.js:9
        ReferenceError: Can't find variable: d3

Я знаю, что это связано с тем, что d3 не определено до window.load, но я не уверен, как правильно определить d3 и методы, которые он использует.

// Karma configuration
// Generated on Thu Oct 29 2015 14:09:24 GMT-0400 (Eastern Daylight Time)

module.exports = function (config) {
    config.set({

        // base path that will be used to resolve all patterns (eg. files, exclude)
        basePath: 'app',


        // frameworks to use
        // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
        frameworks: ['jasmine'],


        // list of files / patterns to load in the browser
        files: [
            'bower_components/angular/angular.js',
            'bower_components/angular-mocks/angular-mocks.js',
            'bower_components/angular-route/angular-route.js',
            'bower_components/d3/d3.js',

            'home/*.js',
            'common/*.js',
            'home/home.module.js',


            'app.js',
            '**/*.module.js',
            '**/*.controller.js',
            '**/*.service.js',

            '**/*.directive.js',
            '**/*.routes.js',

            '**/*.spec.js'
        ],


        // list of files to exclude
        exclude: [
            'bower_components/**/!(angular*|angular-mocks|angular-route*).js'
        ],


        // preprocess matching files before serving them to the browser
        // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
        preprocessors: {
            '!(bower_components)/**/!(*spec).js': 'coverage',
            '*.js': 'coverage'
        },

        // test results reporter to use
        // possible values: 'dots', 'progress'
        // available reporters: https://npmjs.org/browse/keyword/karma-reporter
        reporters: ['progress', 'coverage'],

        coverageReporter: {
            dir: '../coverage/',
            subdir: 'report'
        },

        captureTimeout: 30000,

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


        // start these browsers
        // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
        browsers: ['Chrome', 'Firefox', 'IE', 'PhantomJS'],


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

        // Concurrency level
        // how many browser should be started simultanous
        concurrency: Infinity
    })
};

Изображение 174551

  • 0
    как выглядит ваш karma.config?
  • 0
    добавил к вопросу
Теги:
d3.js
jasmine

1 ответ

1

добавьте d3 в свои файлы karma.conf.js

если ваша структура проекта выглядит так

|--app
| |--app.js
| |--...
|
|--test
| |--karma.conf.js
|
|--bower_components

вам нужно установить basePath на "../", потому что файл karma.conf.js находится внутри тестовой папки, но вы хотите обращаться к файлам через "app/app.js" или "bower_components/..."

config.set({
    basePath: '../' // dont forget the right basePath!
    files:[
        'path/to/d3'
    ],
    ...
})
  • 0
    это было завершено
  • 0
    на что должен указывать basePath? basePath: '../Myapp',
Показать ещё 5 комментариев

Ещё вопросы

Сообщество Overcoder
Наверх
Меню