Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): better support for abilities that are discarded asynchrono…
…usly
- Loading branch information
Showing
8 changed files
with
325 additions
and
79 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...ion/jasmine/examples/screenplay/ability-discard-error-should-not-affect-stage-cue.spec.js
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,61 @@ | ||
const { actorCalled, engage, Interaction } = require('@serenity-js/core'); | ||
|
||
describe('Mocha reporting', () => { | ||
|
||
beforeAll(() => engage(new Actors())); | ||
|
||
describe('A screenplay scenario', () => { | ||
|
||
// even if an ability is not discarded successfully, the subsequent tests should still be executed | ||
it(`fails when discarding an ability fails`, () => | ||
actorCalled('Donald') | ||
.attemptsTo( | ||
NotDoTooMuch(), | ||
)); | ||
|
||
it(`succeeds when ability is discarded successfully`, () => | ||
actorCalled('Alice') | ||
.attemptsTo( | ||
NotDoTooMuch(), | ||
)); | ||
|
||
it(`fails if the ability fails to discard again`, () => | ||
actorCalled('Donald') | ||
.attemptsTo( | ||
NotDoTooMuch(), | ||
)); | ||
}); | ||
}); | ||
|
||
class Actors { | ||
prepare(actor) { | ||
switch (actor.name) { | ||
case 'Donald': | ||
return actor.whoCan(new CauseErrorWhenAbilityDiscarded()); | ||
default: | ||
return actor.whoCan(new SucceedWhenAbilityDiscarded()); | ||
} | ||
} | ||
} | ||
|
||
const NotDoTooMuch = () => Interaction.where(`#actor doesn't do much`, () => void 0); | ||
|
||
class CauseErrorWhenAbilityDiscarded { | ||
static as(actor) { | ||
return actor.abilityTo(CauseErrorWhenAbilityDiscarded); | ||
} | ||
|
||
discard() { | ||
return Promise.reject(new TypeError(`Some internal error in ability`)); | ||
} | ||
} | ||
|
||
class SucceedWhenAbilityDiscarded { | ||
static as(actor) { | ||
return actor.abilityTo(CauseErrorWhenAbilityDiscarded); | ||
} | ||
|
||
discard() { | ||
return Promise.resolve(); | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
...ation/mocha/examples/screenplay/ability-discard-error-should-not-affect-stage-cue.spec.js
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,61 @@ | ||
const { actorCalled, engage, Interaction } = require('@serenity-js/core'); | ||
|
||
describe('Mocha reporting', () => { | ||
|
||
before(() => engage(new Actors())); | ||
|
||
describe('A screenplay scenario', () => { | ||
|
||
// even if an ability is not discarded successfully, the subsequent tests should still be executed | ||
it(`fails when discarding an ability fails`, () => | ||
actorCalled('Donald') | ||
.attemptsTo( | ||
NotDoTooMuch(), | ||
)); | ||
|
||
it(`succeeds when ability is discarded successfully`, () => | ||
actorCalled('Alice') | ||
.attemptsTo( | ||
NotDoTooMuch(), | ||
)); | ||
|
||
it(`fails if the ability fails to discard again`, () => | ||
actorCalled('Donald') | ||
.attemptsTo( | ||
NotDoTooMuch(), | ||
)); | ||
}); | ||
}); | ||
|
||
class Actors { | ||
prepare(actor) { | ||
switch (actor.name) { | ||
case 'Donald': | ||
return actor.whoCan(new CauseErrorWhenAbilityDiscarded()); | ||
default: | ||
return actor.whoCan(new SucceedWhenAbilityDiscarded()); | ||
} | ||
} | ||
} | ||
|
||
const NotDoTooMuch = () => Interaction.where(`#actor doesn't do much`, () => void 0); | ||
|
||
class CauseErrorWhenAbilityDiscarded { | ||
static as(actor) { | ||
return actor.abilityTo(CauseErrorWhenAbilityDiscarded); | ||
} | ||
|
||
discard() { | ||
return Promise.reject(new TypeError(`Some internal error in ability`)); | ||
} | ||
} | ||
|
||
class SucceedWhenAbilityDiscarded { | ||
static as(actor) { | ||
return actor.abilityTo(CauseErrorWhenAbilityDiscarded); | ||
} | ||
|
||
discard() { | ||
return Promise.resolve(); | ||
} | ||
} |
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
Oops, something went wrong.