angular/packages/zone.js/test/browser/HTMLImports.spec.ts
Paul Gschwendtner d2b444a8a2 test: update tests to account for karma-jasmine v5.0.0
Karma jasmine updated the `jasmine-core` dependency. Jasmine is now more
strict when:

* The done callback is invoked multiple times
* The done callback is used, while a promise is also returned
* The done callback is treated as error when e.g. a number is returned
  as first argument. This was the case with `requestAnimationFrame`.
2022-07-18 19:19:00 +02:00

80 lines
2.2 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {ifEnvSupports} from '../test-util';
function supportsImports() {
return 'import' in document.createElement('link');
}
if (supportsImports()) {
describe('HTML Imports', function() {
const testZone = Zone.current.fork({name: 'test'});
it('should work with addEventListener', function(done) {
let link: HTMLLinkElement;
testZone.run(function() {
link = document.createElement('link');
link.rel = 'import';
link.href = 'someUrl';
link.addEventListener('error', function() {
expect(Zone.current).toBe(testZone);
document.head.removeChild(link);
done();
});
});
document.head.appendChild(link!);
});
function supportsOnEvents() {
const link = document.createElement('link');
const linkPropDesc = Object.getOwnPropertyDescriptor(link, 'onerror');
return !(linkPropDesc && linkPropDesc.value === null);
}
(<any>supportsOnEvents).message = 'Supports HTMLLinkElement#onxxx patching';
ifEnvSupports(supportsOnEvents, function() {
it('should work with onerror', function(done) {
let link: HTMLLinkElement;
testZone.run(function() {
link = document.createElement('link');
link.rel = 'import';
link.href = 'anotherUrl';
link.onerror = function() {
expect(Zone.current).toBe(testZone);
document.head.removeChild(link);
done();
};
});
document.head.appendChild(link!);
});
it('should work with onload', function(done) {
let link: HTMLLinkElement;
testZone.run(function() {
link = document.createElement('link');
link.rel = 'import';
link.href = '/base/angular/packages/zone.js/test/assets/import.html';
link.onload = function() {
expect(Zone.current).toBe(testZone);
document.head.removeChild(link);
done();
};
});
document.head.appendChild(link!);
});
});
});
}