/
isPresent.spec.ts
54 lines (45 loc) · 1.99 KB
/
isPresent.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { expect } from '@integration/testing-tools';
import { Ensure } from '@serenity-js/assertions';
import { Actor, AssertionError } from '@serenity-js/core';
import { by, protractor } from 'protractor';
import { BrowseTheWeb, isPresent, Navigate, Target, Wait } from '../../src';
import { pageFromTemplate } from '../fixtures';
describe('isPresent', function() {
const Bernie = Actor.named('Bernie').whoCan(
BrowseTheWeb.using(protractor.browser),
);
const Page = {
Present_Header: Target.the('header').located(by.tagName('h1')),
Non_Existent_Header: Target.the('non-existent header').located(by.tagName('h2')),
};
beforeEach(() => Bernie.attemptsTo(
Navigate.to(pageFromTemplate(`
<html>
<body>
<h1>Hello!</h1>
</body>
</html>
`)),
));
/** @test {isPresent} */
it(`allows the actor flow to continue when the element is present in the DOM`, () => expect(Bernie.attemptsTo(
Wait.until(Page.Present_Header, isPresent()),
Ensure.that(Page.Present_Header, isPresent()),
)).to.be.fulfilled);
/** @test {isPresent} */
it(`breaks the actor flow when element is not present in the DOM`, () => {
return expect(Bernie.attemptsTo(
Ensure.that(Page.Non_Existent_Header, isPresent()),
)).to.be.rejectedWith(AssertionError, `Expected the non-existent header to become present`);
});
/** @test {isPresent} */
it(`contributes to a human-readable description of an assertion`, () => {
expect(Ensure.that(Page.Present_Header, isPresent()).toString())
.to.equal(`#actor ensures that the header does become present`);
});
/** @test {isPresent} */
it(`contributes to a human-readable description of a wait`, () => {
expect(Wait.until(Page.Present_Header, isPresent()).toString())
.to.equal(`#actor waits up to 5s until the header does become present`);
});
});