@ -6,14 +6,14 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ElementFinder, by} from 'protractor';
|
||||
import {by, ElementFinder} from 'protractor';
|
||||
|
||||
declare global {
|
||||
namespace jasmine {
|
||||
interface Matchers<T> {
|
||||
toBeAHero(): Promise<void>;
|
||||
toHaveName(exectedName: string): Promise<void>;
|
||||
}
|
||||
interface Matchers<T> {
|
||||
toBeAHero(): Promise<void>;
|
||||
toHaveName(exectedName: string): Promise<void>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,43 +22,41 @@ const isTitleCased = (text: string) =>
|
||||
|
||||
export function addCustomMatchers() {
|
||||
jasmine.addMatchers({
|
||||
toBeAHero:
|
||||
() => ({
|
||||
compare(actualNg1Hero: ElementFinder | undefined) {
|
||||
const getText = (selector: string) =>
|
||||
actualNg1Hero !.element(by.css(selector)).getText();
|
||||
const result = {
|
||||
message: 'Expected undefined to be an `ng1Hero` ElementFinder.',
|
||||
pass: !!actualNg1Hero &&
|
||||
Promise.all(['.title', 'h2', 'p'].map(getText) as PromiseLike<string>[])
|
||||
.then(([actualTitle, actualName, actualDescription]) => {
|
||||
const pass = (actualTitle === 'Super Hero') && isTitleCased(actualName) &&
|
||||
(actualDescription.length > 0);
|
||||
toBeAHero: () => ({
|
||||
compare(actualNg1Hero: ElementFinder|undefined) {
|
||||
const getText = (selector: string) => actualNg1Hero!.element(by.css(selector)).getText();
|
||||
const result = {
|
||||
message: 'Expected undefined to be an `ng1Hero` ElementFinder.',
|
||||
pass: !!actualNg1Hero &&
|
||||
Promise.all(['.title', 'h2', 'p'].map(getText) as PromiseLike<string>[])
|
||||
.then(([actualTitle, actualName, actualDescription]) => {
|
||||
const pass = (actualTitle === 'Super Hero') && isTitleCased(actualName) &&
|
||||
(actualDescription.length > 0);
|
||||
|
||||
const actualHero =
|
||||
`Hero(${actualTitle}, ${actualName}, ${actualDescription})`;
|
||||
result.message =
|
||||
`Expected ${actualHero}'${pass ? ' not' : ''} to be a real hero.`;
|
||||
const actualHero = `Hero(${actualTitle}, ${actualName}, ${actualDescription})`;
|
||||
result.message =
|
||||
`Expected ${actualHero}'${pass ? ' not' : ''} to be a real hero.`;
|
||||
|
||||
return pass;
|
||||
})
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}),
|
||||
toHaveName: () => ({
|
||||
compare(actualNg1Hero: ElementFinder | undefined, expectedName: string) {
|
||||
const result = {
|
||||
message: 'Expected undefined to be an `ng1Hero` ElementFinder.',
|
||||
pass: !!actualNg1Hero && actualNg1Hero.element(by.css('h2')).getText().then(actualName => {
|
||||
return pass;
|
||||
})
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}),
|
||||
toHaveName: () => ({
|
||||
compare(actualNg1Hero: ElementFinder|undefined, expectedName: string) {
|
||||
const result = {
|
||||
message: 'Expected undefined to be an `ng1Hero` ElementFinder.',
|
||||
pass:
|
||||
!!actualNg1Hero && actualNg1Hero.element(by.css('h2')).getText().then(actualName => {
|
||||
const pass = actualName === expectedName;
|
||||
result.message =
|
||||
`Expected Hero(${actualName})${pass ? ' not' : ''} to have name '${expectedName}'.`;
|
||||
result.message = `Expected Hero(${actualName})${pass ? ' not' : ''} to have name '${
|
||||
expectedName}'.`;
|
||||
return pass;
|
||||
})
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}),
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}),
|
||||
} as any);
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ElementArrayFinder, ElementFinder, browser, by, element} from 'protractor';
|
||||
import {browser, by, element, ElementArrayFinder, ElementFinder} from 'protractor';
|
||||
|
||||
import {verifyNoBrowserErrors} from '../../../../../test-utils';
|
||||
|
||||
import {addCustomMatchers} from './e2e_util';
|
||||
|
Reference in New Issue
Block a user