Files
angular__angular/e2e/util/asserts.ts
T
Paul Gschwendtner 326f8bb32f build: run e2e tests with bazel (#14656)
* Builds the e2e app with Bazel
* Serves the e2e app with Bazel
* Runs the e2e tests with Bazel protractor rules
2019-01-11 14:43:04 -08:00

40 lines
1.3 KiB
TypeScript

import {browser} from 'protractor';
import {getElement, FinderResult, waitForElement} from './query';
import {Point} from './actions';
/**
* Asserts that an element exists.
*/
export async function expectToExist(selector: string, expected = true) {
await waitForElement(selector).then((isPresent: boolean) => {
expect(isPresent).toBe(expected, `Expected "${selector}"${expected ? '' : ' not'} to exist`);
});
}
/**
* Asserts that an element is focused.
*/
export async function expectFocusOn(element: FinderResult, expected = true) {
expect(await browser.driver.switchTo().activeElement().getId()).toBe(
await getElement(element).getId(), `Expected element${expected ? '' : ' not'} to be focused.`);
}
/**
* Asserts that an element has a certain location.
*/
export async function expectLocation(element: FinderResult, {x, y}: Point) {
await getElement(element).getLocation().then((location: Point) => {
expect(Math.round(location.x)).toEqual(Math.round(x));
expect(Math.round(location.y)).toEqual(Math.round(y));
});
}
/**
* Asserts that one element is aligned with another.
*/
export async function expectAlignedWith(element: FinderResult, otherElement: FinderResult) {
await getElement(otherElement).getLocation().then((location: Point) => {
expectLocation(getElement(element), location);
});
}