Skip to content

Commit

Permalink
test(beforeandaftersteps.feature): cucumber syntax for steps definition
Browse files Browse the repository at this point in the history
  • Loading branch information
lgandecki committed Aug 21, 2019
1 parent b232286 commit ddb5a46
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions cypress/support/step_definitions/before_and_after_steps.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,52 @@
/* global given, when, then, before, after */
/* eslint-env mocha */
/* eslint-disable import/no-extraneous-dependencies */
const {
Before,
After,
Given,
Then,
When
} = require("cypress-cucumber-preprocessor/steps");

let beforeCounter = 0;
let beforeWithTagCounter = 0;

before(() => {
Before(() => {
beforeCounter += 1;
});

before({ tags: "@withTaggedBefore" }, () => {
Before({ tags: "@withTaggedBefore" }, () => {
beforeWithTagCounter += 1;
});

before({ tags: "@willNeverRun" }, () => {
Before({ tags: "@willNeverRun" }, () => {
throw new Error("XXX: before hook unexpectedly called.");
});

after({ tags: "@willNeverRun" }, () => {
After({ tags: "@willNeverRun" }, () => {
throw new Error("XXX: after hook unexpectedly called.");
});

after(() => {
After(() => {
beforeCounter = 0;
});

after({ tags: "@withTaggedAfter" }, () => {
After({ tags: "@withTaggedAfter" }, () => {
beforeWithTagCounter = 0;
});

given("I do something", () => {});
Given("I do something", () => {});

when("Something else", () => {});
When("Something else", () => {});

then("Before was called once", () => {
Then("Before was called once", () => {
expect(beforeCounter).to.equal(1);
});

then("Before with tag was called once", () => {
Then("Before with tag was called once", () => {
expect(beforeWithTagCounter).to.equal(1);
});

then("Before was not called", () => {
Then("Before was not called", () => {
expect(beforeCounter).to.equal(1);
});

0 comments on commit ddb5a46

Please sign in to comment.