Skip to content

Update api_reference.md #661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 42 additions & 38 deletions docs/support_files/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,87 @@

## API Reference

All support files that export a function will be
called with a context that exposes the following methods:
All support files that export a function will be called with a context that exposes the following methods:

---

#### this.After([options,] code)
#### `this.After([options,] fn)`

Defines a hook which is run after each scenario.

* `options` - object with the following keys
* `tags` - array of tags used to apply this hook to only specific scenarios
* `timeout` - hook specific timeout to override the default timeout
* `code` - a javascript function. The first argument will be the current running scenario.
See [Cucumber.Api.Scenario](https://github.com/cucumber/cucumber-js/blob/master/lib/cucumber/api/scenario.js)
for more information. May optionally take an additional argument if using the asynchronous callback interface.
* `options`: An object with the following keys:
- `tags`: An array of tags used to apply this hook to only specific scenarios.
- `timeout`: A hook-specific timeout, to override the default timeout.
* `fn`: A function, defined as follows:
- The first argument will be the current running scenario.
(See [`Cucumber.Api.Scenario`](https://github.com/cucumber/cucumber-js/blob/master/lib/cucumber/api/scenario.js) for more information.)
- When using the asynchronous callback interface, have one final argument for the callback function.

Multiple *After* hooks are executed in the **reverse** order that they were defined.
Multiple `After` hooks are executed in the **reverse** order that they are defined.

---

#### this.Before([options,] code)
#### `this.Before([options,] fn)`

Defines a hook which is run before each scenario. Same interface as *this.After*.
Multiple *Before* hooks are executed in the order that they were defined.
Defines a hook which is run before each scenario. Same interface as `this.After`.

Multiple `Before` hooks are executed in the order that they are defined.

---

#### this.defineStep([options,] pattern, code)
#### `this.defineStep([options,] pattern, fn)`

Defines a step.

Defines a step. *Aliases: this.Given, this.When, this.Then*
Aliases: `this.Given`, `this.When`, `this.Then`.

* `options` - object with the following keys
* `timeout` - step specific timeout to override the default timeout
* `pattern` - regex or string pattern to match against a gherkin step
* `code` - a javascript function. Should have one argument for each capture in the
regular expression. May have an additional argument if the gherkin step has
a doc string or data table. Finally may optionally take an additional argument
as a callback if using that interface.
* `options`: An object with the following keys:
- `timeout`: A step-specific timeout, to override the default timeout.
* `pattern`: A regex or string pattern to match against a gherkin step.
* `fn`: A function, which should be defined as follows:
- Should have one argument for each capture in the regular expression.
- May have an additional argument if the gherkin step has a docstring or data table.
- When using the asynchronous callback interface, have one final argument for the callback function.

---

#### this.Given([options,] pattern, code)
#### `this.Given([options,] pattern, fn)`

Alias of *this.defineStep*
Alias of `this.defineStep`.

---

#### this.registerHandler(event, [options,] code)
#### `this.registerHandler(event, [options,] fn)`

* `event` - one of the supported event names listed [here](./event_handlers.md)
* `options` - object with the following keys
* `timeout` - step specific timeout to override the default timeout
* `code` - a javascript function. The first argument is the object as defined [here](./event_handlers.md). May optionally take an additional argument
as a callback if using that interface.
* `event`: One of the supported event names [listed here](./event_handlers.md).
* `options`: An object with the following keys:
- `timeout`: A step-specific timeout, to override the default timeout.
* `fn`: A function, defined as follows:
- The first argument is the object as defined [here](./event_handlers.md).
- When using the asynchronous callback interface, have one final argument for the callback function.

---

#### this.setDefaultTimeout(milliseconds)
#### `this.setDefaultTimeout(milliseconds)`

Set the default timeout for asynchronous steps. Default is `5000` milliseconds.
Set the default timeout for asynchronous steps. Defaults to `5000` milliseconds.

---

#### this.Then([options,] pattern, code)
#### `this.Then([options,] pattern, fn)`

Alias of *this.defineStep*
Alias of `this.defineStep`.

---

#### this.When([options,] pattern, code)
#### `this.When([options,] pattern, fn)`

Alias of *this.defineStep*
Alias of `this.defineStep`.

---

#### this.World
#### `this.World`

Set to a custom world constructor to override the default (`function () {}`).
Set a custom world constructor, to override the default world constructor (`function () {}`).

**Note:** The World constructor was made strictly synchronous in *[v0.8.0](https://github.com/cucumber/cucumber-js/releases/tag/v0.8.0)*.