2015-12-30 2 views
0

Привет всем, я пытаюсь выполнить некоторые тесты жасмина/кармы в приложении d3, однако я не могу пройти мимо этой ошибки: ReferenceError: Не удается найти переменную: 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 
    }) 
}; 

enter image description here

+0

Как выглядит ваш karma.config? – Gustav

+0

добавлено в вопрос – user2402107

ответ

0

добавить 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

Это было заполнено – user2402107

+0

Что такое basePath, который должен указывать тоже? basePath: '../Myapp', – user2402107

+0

зависит от местоположения файла karma.conf.js, я отредактирую свой ответ – Lusk116