我正在尝试ngUpgrade
从 ng1 移动到 ng2,并在升级过程中保持我的 Karma/Jasmine 测试通过,但我遇到了一个我无法弄清楚的错误。
我已将 Service ( Data
) 升级为 ng2 @Injectable
,并用于upgradeAdapter.downgradeNg2Provider
将其注入到我的 ng1 应用程序中。它在生产代码中运行良好。
但是当我尝试在我的测试中 $inject 它时,我得到了这个错误:
Error: [$injector:unpr] Unknown provider: ng2.InjectorProvider <- ng2.Injector <- Data
有人有在 ngUpgrade 中间对代码进行单元测试的工作示例吗?我的堆栈是基于 Webpack 的。我尝试遵循并转换systemjs 指南,但没有任何运气。
业力.conf.js:
module.exports = function (config) {
config.set({
// base path used to resolve all patterns
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files/patterns to load in the browser
files: [{ pattern: 'spec.bundle.js', watched: false }],
// files to exclude
exclude: [],
plugins: [
require('karma-phantomjs-launcher'),
require('karma-jasmine'),
require('karma-webpack')
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: { 'spec.bundle.js': ['webpack'] },
webpack: require('./webpack.config'),
webpackServer: {
noInfo: true // prevent console spamming when running in Karma!
},
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable colors in the output
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,
// toggle whether to watch files and rerun tests upon incurring changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
// if true, Karma runs tests once and exits
singleRun: false
});
};
spec.bundle.js
import 'angular';
import 'angular-mocks';
import 'es6-shim';
import 'reflect-metadata';
import 'angular2/src/core/di';
import test from 'angular2/testing';
import browser from 'angular2/platform/testing/browser';
test.setBaseTestProviders(browser.TEST_BROWSER_PLATFORM_PROVIDERS,
browser.TEST_BROWSER_APPLICATION_PROVIDERS);
let context = require.context('./src', true, /\.spec\.js/);
context.keys().forEach(context);