@ -5,8 +5,9 @@
|
||||
* 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 {APP_ID, NgModule, NgZone, PLATFORM_INITIALIZER, PlatformRef, StaticProvider, createPlatformFactory, platformCore} from '@angular/core';
|
||||
import {APP_ID, createPlatformFactory, NgModule, NgZone, PLATFORM_INITIALIZER, platformCore, PlatformRef, StaticProvider} from '@angular/core';
|
||||
import {BrowserModule, ɵBrowserDomAdapter as BrowserDomAdapter, ɵELEMENT_PROBE_PROVIDERS as ELEMENT_PROBE_PROVIDERS} from '@angular/platform-browser';
|
||||
|
||||
import {BrowserDetection, createNgZone} from './browser_util';
|
||||
|
||||
function initBrowserTests() {
|
||||
|
@ -19,11 +19,17 @@ export class BrowserDetection {
|
||||
return getDOM() ? getDOM().getUserAgent() : '';
|
||||
}
|
||||
|
||||
static setup() { return new BrowserDetection(null); }
|
||||
static setup() {
|
||||
return new BrowserDetection(null);
|
||||
}
|
||||
|
||||
constructor(ua: string|null) { this._overrideUa = ua; }
|
||||
constructor(ua: string|null) {
|
||||
this._overrideUa = ua;
|
||||
}
|
||||
|
||||
get isFirefox(): boolean { return this._ua.indexOf('Firefox') > -1; }
|
||||
get isFirefox(): boolean {
|
||||
return this._ua.indexOf('Firefox') > -1;
|
||||
}
|
||||
|
||||
get isAndroid(): boolean {
|
||||
return this._ua.indexOf('Mozilla/5.0') > -1 && this._ua.indexOf('Android') > -1 &&
|
||||
@ -31,9 +37,13 @@ export class BrowserDetection {
|
||||
this._ua.indexOf('IEMobile') == -1;
|
||||
}
|
||||
|
||||
get isEdge(): boolean { return this._ua.indexOf('Edge') > -1; }
|
||||
get isEdge(): boolean {
|
||||
return this._ua.indexOf('Edge') > -1;
|
||||
}
|
||||
|
||||
get isIE(): boolean { return this._ua.indexOf('Trident') > -1; }
|
||||
get isIE(): boolean {
|
||||
return this._ua.indexOf('Trident') > -1;
|
||||
}
|
||||
|
||||
get isWebkit(): boolean {
|
||||
return this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Edge') == -1 &&
|
||||
@ -45,7 +55,9 @@ export class BrowserDetection {
|
||||
this._ua.indexOf('IEMobile') == -1;
|
||||
}
|
||||
|
||||
get isSlow(): boolean { return this.isAndroid || this.isIE || this.isIOS7; }
|
||||
get isSlow(): boolean {
|
||||
return this.isAndroid || this.isIE || this.isIOS7;
|
||||
}
|
||||
|
||||
// The Intl API is only natively supported in Chrome, Firefox, IE11 and Edge.
|
||||
// This detector is needed in tests to make the difference between:
|
||||
@ -67,13 +79,17 @@ export class BrowserDetection {
|
||||
this._ua.indexOf('Edge') == -1;
|
||||
}
|
||||
|
||||
get supportsCustomElements() { return (typeof(<any>global).customElements !== 'undefined'); }
|
||||
|
||||
get supportsDeprecatedCustomCustomElementsV0() {
|
||||
return (typeof(document as any).registerElement !== 'undefined');
|
||||
get supportsCustomElements() {
|
||||
return (typeof (<any>global).customElements !== 'undefined');
|
||||
}
|
||||
|
||||
get supportsRegExUnicodeFlag(): boolean { return RegExp.prototype.hasOwnProperty('unicode'); }
|
||||
get supportsDeprecatedCustomCustomElementsV0() {
|
||||
return (typeof (document as any).registerElement !== 'undefined');
|
||||
}
|
||||
|
||||
get supportsRegExUnicodeFlag(): boolean {
|
||||
return RegExp.prototype.hasOwnProperty('unicode');
|
||||
}
|
||||
|
||||
get supportsShadowDom() {
|
||||
const testEl = document.createElement('div');
|
||||
@ -203,10 +219,10 @@ export function setCookie(name: string, value: string) {
|
||||
}
|
||||
|
||||
export function supportsWebAnimation(): boolean {
|
||||
return typeof(<any>Element).prototype['animate'] === 'function';
|
||||
return typeof (<any>Element).prototype['animate'] === 'function';
|
||||
}
|
||||
|
||||
export function hasStyle(element: any, styleName: string, styleValue?: string | null): boolean {
|
||||
export function hasStyle(element: any, styleName: string, styleValue?: string|null): boolean {
|
||||
const value = element.style[styleName] || '';
|
||||
return styleValue ? value == styleValue : value.length > 0;
|
||||
}
|
||||
|
@ -123,7 +123,9 @@ export const expect: <T = any>(actual: T) => NgMatchers<T> = _global.expect;
|
||||
return '' + m;
|
||||
}
|
||||
const res: any[] = [];
|
||||
m.forEach((v: any, k: any) => { res.push(`${String(k)}:${String(v)}`); });
|
||||
m.forEach((v: any, k: any) => {
|
||||
res.push(`${String(k)}:${String(v)}`);
|
||||
});
|
||||
return `{ ${res.join(',')} }`;
|
||||
};
|
||||
|
||||
@ -141,7 +143,7 @@ _global.beforeEach(function() {
|
||||
return pass;
|
||||
} else {
|
||||
// TODO(misko): we should change the return, but jasmine.d.ts is not null safe
|
||||
return undefined !;
|
||||
return undefined!;
|
||||
}
|
||||
});
|
||||
jasmine.addMatchers({
|
||||
@ -149,7 +151,12 @@ _global.beforeEach(function() {
|
||||
return {
|
||||
compare: function(actual: any) {
|
||||
const pass = typeof actual === 'object' && typeof actual.then === 'function';
|
||||
return {pass: pass, get message() { return 'Expected ' + actual + ' to be a promise'; }};
|
||||
return {
|
||||
pass: pass,
|
||||
get message() {
|
||||
return 'Expected ' + actual + ' to be a promise';
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
@ -174,7 +181,9 @@ _global.beforeEach(function() {
|
||||
const actualText = elementText(actual);
|
||||
return {
|
||||
pass: actualText == expectedText,
|
||||
get message() { return 'Expected ' + actualText + ' to be equal to ' + expectedText; }
|
||||
get message() {
|
||||
return 'Expected ' + actualText + ' to be equal to ' + expectedText;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
@ -188,7 +197,8 @@ _global.beforeEach(function() {
|
||||
return {
|
||||
pass: hasClass(actual, className) == !isNot,
|
||||
get message() {
|
||||
return `Expected ${actual.outerHTML} ${isNot ? 'not ' : ''}to contain the CSS class "${className}"`;
|
||||
return `Expected ${actual.outerHTML} ${
|
||||
isNot ? 'not ' : ''}to contain the CSS class "${className}"`;
|
||||
}
|
||||
};
|
||||
};
|
||||
@ -203,8 +213,9 @@ _global.beforeEach(function() {
|
||||
allPassed = hasStyle(actual, styles);
|
||||
} else {
|
||||
allPassed = Object.keys(styles).length !== 0;
|
||||
Object.keys(styles).forEach(
|
||||
prop => { allPassed = allPassed && hasStyle(actual, prop, styles[prop]); });
|
||||
Object.keys(styles).forEach(prop => {
|
||||
allPassed = allPassed && hasStyle(actual, prop, styles[prop]);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
@ -212,7 +223,8 @@ _global.beforeEach(function() {
|
||||
get message() {
|
||||
const expectedValueStr = typeof styles === 'string' ? styles : JSON.stringify(styles);
|
||||
return `Expected ${actual.outerHTML} ${!allPassed ? ' ' : 'not '}to contain the
|
||||
CSS ${typeof styles === 'string' ? 'property' : 'styles'} "${expectedValueStr}"`;
|
||||
CSS ${typeof styles === 'string' ? 'property' : 'styles'} "${
|
||||
expectedValueStr}"`;
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -225,7 +237,9 @@ _global.beforeEach(function() {
|
||||
const errorMessage = actual.toString();
|
||||
return {
|
||||
pass: errorMessage.indexOf(expectedText) > -1,
|
||||
get message() { return 'Expected ' + errorMessage + ' to contain ' + expectedText; }
|
||||
get message() {
|
||||
return 'Expected ' + errorMessage + ' to contain ' + expectedText;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
@ -244,8 +258,8 @@ _global.beforeEach(function() {
|
||||
return {
|
||||
pass: missedMethods.length == 0,
|
||||
get message() {
|
||||
return 'Expected ' + actualObject + ' to have the following methods: ' +
|
||||
missedMethods.join(', ');
|
||||
return 'Expected ' + actualObject +
|
||||
' to have the following methods: ' + missedMethods.join(', ');
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -262,8 +276,8 @@ _global.beforeEach(function() {
|
||||
if (!(actualFixture instanceof ComponentFixture)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: msgFn(
|
||||
`Expected actual to be of type \'ComponentFixture\' [actual=${actualFixture.constructor.name}]`)
|
||||
message: msgFn(`Expected actual to be of type \'ComponentFixture\' [actual=${
|
||||
actualFixture.constructor.name}]`)
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user