Skip to content

Commit

Permalink
docs(extensions): init documentation on extensions internals
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte committed Jun 28, 2017
1 parent e854a25 commit 9bfba8e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Great for testing APIs built upon Express, Koa, HAPI, Loopback and others.
- [Posting data](#posting-data)
- [Using values issued by a previous request](#using-values-issued-by-a-previous-request)
- [Type system](#type-system)
- [Extensions](#extensions)
- [state](#state-extension)
- [http API](#http-api-extension)
- [Examples](#examples)

## Installation
Expand Down Expand Up @@ -188,9 +191,47 @@ which will generate the following payload:
}
```

## Extensions

This module is composed of several extensions.

### state extension

The state extension is a simple helper used to persist state between steps & eventually scenarios
(but you should try to avoid coupling scenarios).

It's involved for example when [you want to collect values issued by a previous request](#using-values-issued-by-a-previous-request)
when using the [http API extension](#http-api-extension).

When installed, you can access it from the global cucumber context in your own step definitions.

```javascript
defineSupportCode(({ When }) => {
When(/^I do something useful$/, function() {
const stateValue = this.state.get('whatever')
//
})
})
```

### http API extension

The http API extension relies on the [state extension](#state-extension),
so make sure it's registered prior to installation.

When installed, you can access it from the global cucumber context in your own step definitions.

```javascript
defineSupportCode(({ When }) => {
When(/^I do something useful$/, function() {
return this.httpApi.makeRequest(/**/)
})
})
```

## Examples

This repository comes with few examples, in order to run them invoke the following script:
This repository comes with few examples, in order to run them, invoke the following script:

```sh
yarn run examples
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/http_api/extend_world.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const client = require('./client')

module.exports = world => {
if (!Helper.hasExtension(world, 'state')) {
throw new Error(`Unable to init "http_api" context as it requires "state" context which is not installed`)
throw new Error(`Unable to init "http_api" extension as it requires "state" extension which is not installed`)
}

world.httpApiClient = client
Expand Down

0 comments on commit 9bfba8e

Please sign in to comment.