用于Jasmine测试的延迟加载模块。 Angularjs

时间:2018-05-03 07:15:26

标签: angularjs webpack jasmine karma-jasmine lazy-loading

我的应用程序中有一些模块是延迟加载的。 但它们不能用于茉莉花测试。我无法在beforeEach或其他任何地方初始化/加载模块。 问题是我无法找到有关此问题的任何信息。是否可以为我的情况做这件事。

我的业力配置:

config.set({

   plugins: [

       require('karma-babel-preprocessor'),

       require('karma-chrome-launcher'),

       require('karma-jasmine'),

       require('karma-phantomjs-launcher'),

       require('karma-safari-launcher'),

       require('karma-spec-reporter'),

   ],

   preprocessors: {

       'app/**/*.spec.js': ['babel'],

       'app/components/my.lazy.module.js': ['babel']

   },

   babelPreprocessor: {

       options: {

           presets: ['es2015'],

           plugins: ['syntax-dynamic-import']

       }

   },

   files: [

       'app/dest/app.js',

       'app/dest/*.bundle.js',

       'app/components/my.lazy.module.js',

       'node_modules/angular-mocks/angular-mocks.js',

       'node_modules/babel-polyfill/dist/polyfill.js',

       'app/**/*.spec.js'

   ],


    frameworks: [

       'jasmine'

   ],


    reporters: [

       'spec'

   ],

我尝试以这种方式加载它:

beforeEach(inject(($ocLazyLoad) => {

   import(/* webpackChunkName: "my.lazy" */ 'base/app/components/my.lazy.module.js')

       .then(mod => {

           return $ocLazyLoad.inject(mod.MyLazyModule);

       })

 }));

可以在带有webpack的angularjs中完成吗?我究竟做错了什么?请帮帮我

0 个答案:

没有答案
相关问题