3c66b100dd
The `DomAdapter` is present in all Angular apps and its methods aren't tree shakeable. These changes remove the methods that either aren't being used anymore or were only used by our own tests. Note that these changes aren't breaking, because the adapter is an internal API. The following methods were removed: * `getProperty` - only used within our own tests. * `log` - Guaranteed to be defined on `console`. * `logGroup` and `logGroupEnd` - Only used in one place. It was in the DomAdapter for built-in null checking. * `logGroupEnd` - Only used in one place. It was placed in the DomAdapter for built in null checking. * `performanceNow` - Only used in one place that has to be invoked through the browser console. * `supportsCookies` - Unused. * `getCookie` - Unused. * `getLocation` and `getHistory` - Only used in one place which appears to have access to the DOM already, because it had direct accesses to `window`. Furthermore, even if this was being used in a non-browser context already, the `DominoAdapter` was set up to throw an error. The following APIs were changed to be more compact: * `supportsDOMEvents` - Changed to a readonly property. * `remove` - No longer returns the removed node. PR Close #41102
51 lines
1.4 KiB
TypeScript
51 lines
1.4 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 {ɵgetDOM as getDOM} from '@angular/common';
|
|
import {ServerStylesHost} from '@angular/platform-server/src/styles_host';
|
|
|
|
|
|
(function() {
|
|
if (getDOM().supportsDOMEvents) return; // NODE only
|
|
|
|
describe('ServerStylesHost', () => {
|
|
let ssh: ServerStylesHost;
|
|
let documentHead: Element;
|
|
beforeEach(() => {
|
|
const doc = getDOM().createHtmlDocument();
|
|
ssh = new ServerStylesHost(doc, '');
|
|
documentHead = doc.head;
|
|
doc.querySelector('title')?.remove();
|
|
});
|
|
|
|
it('should add existing styles', () => {
|
|
ssh.addStyles(['a {};']);
|
|
expect(documentHead.innerHTML).toEqual('<style>a {};</style>');
|
|
});
|
|
|
|
it('should add new styles to hosts', () => {
|
|
ssh.addStyles(['a {};']);
|
|
expect(documentHead.innerHTML).toEqual('<style>a {};</style>');
|
|
});
|
|
|
|
it('should add styles only once to hosts', () => {
|
|
ssh.addStyles(['a {};']);
|
|
ssh.addStyles(['a {};']);
|
|
expect(documentHead.innerHTML).toEqual('<style>a {};</style>');
|
|
});
|
|
|
|
it('should remove style nodes on destroy', () => {
|
|
ssh.addStyles(['a {};']);
|
|
expect(documentHead.innerHTML).toEqual('<style>a {};</style>');
|
|
|
|
ssh.ngOnDestroy();
|
|
expect(documentHead.innerHTML).toEqual('');
|
|
});
|
|
});
|
|
})();
|