forked from Klaveness-Digital/cypress-cucumber-preprocessor
-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(beforeandaftersteps.feature): cucumber syntax for steps definition
- Loading branch information
Showing
1 changed file
with
19 additions
and
12 deletions.
There are no files selected for viewing
31 changes: 19 additions & 12 deletions
31
cypress/support/step_definitions/before_and_after_steps.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 |
---|---|---|
@@ -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); | ||
}); |