Skip to content
Permalink
Browse files
fix(protractor): Clear can clear a value of an empty field
  • Loading branch information
jan-molak committed Jul 14, 2020
1 parent af51f66 commit 6bd85ffc4d4a5169652cb8d1a5d743e47e9efcc2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
@@ -1,3 +1,5 @@
import 'mocha';

import { expect } from '@integration/testing-tools';
import { Ensure, equals } from '@serenity-js/assertions';
import { actorCalled, LogicError } from '@serenity-js/core';
@@ -30,6 +32,24 @@ describe('Clear', () => {
Ensure.that(Value.of(Form.Field), equals('')),
));

/** @test {Clear} */
/** @test {Clear.theValueOf} */
it('allows the actor to clear the value of an empty input with no "value" attribute', () => actorCalled('Bernie').attemptsTo(
Navigate.to(pageFromTemplate(`
<html>
<body>
<form>
<input type="text" id="field" />
</form>
</body>
</html>
`)),

Clear.theValueOf(Form.Field),

Ensure.that(Value.of(Form.Field), equals('')),
));

/** @test {Clear} */
/** @test {Clear.theValueOf} */
it('allows the actor to clear the value of an input field', () => actorCalled('Bernie').attemptsTo(
@@ -27,7 +27,7 @@ export class Clear extends Interaction {
performAs(actor: UsesAbilities & AnswersQuestions): PromiseLike<void> {
return withAnswerOf(actor, this.field, (elf: ElementFinder) =>
elf.getAttribute('value').then(value => {
if (value == null) {
if (value === null) {
throw new LogicError(
`${ this.capitaliseFirstLetter(this.field.toString()) } doesn't seem to have a 'value' attribute that could be cleared.`,
);

0 comments on commit 6bd85ff

Please sign in to comment.