karma-ng-html2js-preprocessor
karma-ng-html2js-preprocessor copied to clipboard
Test pass only if singleRun is false
I'm experiencing an issue where this test pass only if singleRun is false.
When I set singleRun to true the test fails because template.html() is empty.
I've tried to add timeouts or to fire more digests but it always fails.
It seems that the template of my-app-language-switcher (it uses templateUrl) is not correctly loaded and the directive is not compiled if singleRun is true: I've tried to console.log the document.body after the digest and the directive is not compiled.
-- karma conf file
ngHtml2JsPreprocessor: {
moduleName: 'templates',
stripPrefix: 'app/',
},
preprocessors: {
'test/unit/**/*.js': ['babel'],
'app/views/directive/*.html': ['ng-html2js']
},
files: [
'test/res/inject-raven.js',
'app_babel/scripts/**/*.js',
'app/views/directive/*.html',
'test/unit/**/*.js'
]
-- test
describe('Language switcher suite', () => {
let $compile, $scope;
beforeEach(angular.mock.module('myApp'));
beforeEach(angular.mock.module('templates'));
beforeEach(inject((_$compile_, _$rootScope_) => {
$compile = _$compile_;
$scope = _$rootScope_.$new();
}));
it('Should show the language switcher', () => {
// pending();
const template = $compile('<my-app-language-switcher />')($scope);
document.body.appendChild(template[0]);
$scope.$digest();
expect(template.html()).toContain('flag-icon-gb');
});
});
It works if I use singleRun true and Chrome as the browser. The test fails if it runs on phantomjs.