1
次の単体テストはHTMLでのインポートがサポートされているためChromeで動作しますが、PhantomJS(およびその他のブラウザでも問題なく動作します) )。jantmine/karmaを使ってPhantomJSの角度コンポーネントをインポートする
私は、インポート( 'webcomponents.js/HTMLImports.min.js')をpolyfillしようとしていますが、何の効果もありません。
karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
plugins: [
'karma-phantomjs-launcher',
'karma-chrome-launcher',
'karma-jasmine'
],
files: [
'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',
'node_modules/webcomponents.js/HTMLImports.min.js',
'component/so-example.html',
'test/test.spec.js'
],
port: 9876,
browsers: ['Chrome', 'PhantomJS']
});
};
成分/ SO-example.html
<script>
(function() {
var soExampleComponent = {
transclude: true,
bindings: {
number: '@'
},
template: '<span class="compiled">{{$ctrl.number}}</span>'
};
angular.module('so.components.example', []).component('soExample', soExampleComponent);
})();
</script>
テスト/ test.spec.js
describe('<so-example>', function() {
var $scope, el;
beforeEach(module('so.components.example'));
beforeEach(inject(function ($compile, $rootScope) {
$scope = $rootScope.$new();
el = $compile('<so-example number="{{ 3 }}"></so-example>')($scope)[0];
$scope.$digest();
}));
it('should import and compile', function() {
expect(el.querySelector('.compiled').textContent).toBe('3');
});
});
PhantomJS
からエラー[email protected]:/Temp/so-example/node_modules/angular/angular.js:322:24
[email protected]:/Temp/so-example/node_modules/angular/angular.js:4591:12
[email protected]:/Temp/so-example/node_modules/angular/angular.js:4513:30
[email protected]:/Temp/so-example/node_modules/angular-mocks/angular-mocks.js:3060:60
C:/Temp/so-example/node_modules/angular/angular.js:4631:53
TypeError: undefined is not an object (evaluating 'el.querySelector') in C:/Temp/so-example/test/test.spec.js (line 14)
C:/Temp/so-example/test/test.spec.js:14:14
コンポーネントがHTMLファイル内にあるのはなぜですか? – Phil
これは、不要なビルドステップ(それらを連結)を導入することなく、スタイルとスクリプトをまとめて素敵なコンポーネント(ラWebコンポーネント)にまとめることを可能にします。例に。 期待どおり、私はそれを自分の.jsファイルに取り出すと正常に動作します。 –