Skip to content

Commit

Permalink
implement basic assert in cucumber world
Browse files Browse the repository at this point in the history
  • Loading branch information
customcommander committed Sep 7, 2024
1 parent bac858c commit e259c2b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/core/001.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Feature:

Scenario:
Given I start playing
Then I will have fun
Then the current turn is 1
8 changes: 4 additions & 4 deletions test/steps.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Given, When} from '@cucumber/cucumber';
import {Given, Then} from '@cucumber/cucumber';

Given('I start playing', function () {

this.start();
});

When('I will have fun', function () {

Then('the current turn is {int}', async function (expected_turn) {
await this.assert(({turn}) => turn === expected_turn);
});

10 changes: 10 additions & 0 deletions test/world.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import {World, setWorldConstructor} from '@cucumber/cucumber';
import {waitFor} from 'xstate';
import game from '../src/game.js';

setWorldConstructor(class extends World {

constructor(options) {
super(options);
}

start() {
this.game = game();
this.game.start();
}

async assert(predicate) {
await waitFor(this.game, ({context}) => predicate(context), {timeout: 2000});
}
});

0 comments on commit e259c2b

Please sign in to comment.