Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(screenplay):
See
- a screenplay-style way of executing assertions
See allows the Actor to perform an intra-flow verification and stop the scenario should the verification fail. Usage: `actor.attemptsTo(See.that(<Question>, (result) => expect(result).to.eventually.equal('foo')))`
- Loading branch information
Showing
11 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import sinon = require('sinon'); | ||
import expect = require('../../../expect'); | ||
import { AssertionError } from 'chai'; | ||
|
||
import { Actor, Question, See, UsesAbilities } from '../../../../src/serenity/screenplay'; | ||
|
||
describe('Tasks', () => { | ||
|
||
describe('See', () => { | ||
|
||
class SomeResult implements Question<string> { | ||
answeredBy(actor: UsesAbilities): PromiseLike<string>|string { | ||
return Promise.resolve('some value'); | ||
} | ||
} | ||
|
||
it ('allows actor to verify a condition', () => { | ||
let actor = Actor.named('James'); | ||
|
||
let promise = See. | ||
that(new SomeResult(), r => expect(r).to.eventually.equal('some value')). | ||
performAs(actor); | ||
|
||
return expect(promise).to.be.eventually.fulfilled; | ||
}); | ||
|
||
it ('rejects the promise if the condition is not met', () => { | ||
let actor = Actor.named('James'); | ||
|
||
let promise = See. | ||
that(new SomeResult(), r => expect(r).to.eventually.equal('other value')). | ||
performAs(actor); | ||
|
||
return expect(promise).to.be.eventually.rejectedWith(AssertionError, 'expected \'some value\' to equal \'other value\''); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './actor'; | ||
export * from './performables'; | ||
export * from './question'; | ||
export * from './tasks'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './see'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { AnswersQuestions, Performable, Question } from '..'; | ||
import { step } from '../../recording/step_annotation'; | ||
|
||
export type AssertionFn<S> = (subject: S) => PromiseLike<void>; | ||
|
||
export class See<S> implements Performable { | ||
static that<S>(subject: Question<S>, verifier: AssertionFn<S>) { | ||
return new See(subject, verifier); | ||
} | ||
|
||
@step('{0} looks at #question') | ||
performAs(actor: AnswersQuestions): PromiseLike<void> { | ||
return this.assert(actor.toSee(this.question)); | ||
} | ||
|
||
constructor(private question: Question<S>, private assert: AssertionFn<S>) { | ||
} | ||
} |