Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Commit

Permalink
Add language hints to the code blocks in the readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
Dbuggerx authored and Lukas-Kullmann committed May 31, 2019
1 parent 0bf764e commit ceb40e2
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,40 +196,46 @@ Example:

1. Create a _ParameterTypeRegistry_ (e.g. _myCustomParamRegistry.js_):

const { ParameterTypeRegistry, ParameterType } = require('cucumber-expressions');
```js
const { ParameterTypeRegistry, ParameterType } = require('cucumber-expressions');

class Color {
constructor(name) {
this.name = `${name} color`;
}
class Color {
constructor(name) {
this.name = `${name} color`;
}
}

const registry = new ParameterTypeRegistry();
const registry = new ParameterTypeRegistry();

registry.defineParameterType(
new ParameterType(
'color', // name of the parameter
/red|blue|yellow/, // regexp used to match
Color, // the parameter's type
name => new Color(name) // transformer function
)
);
registry.defineParameterType(
new ParameterType(
'color', // name of the parameter
/red|blue|yellow/, // regexp used to match
Color, // the parameter's type
name => new Color(name) // transformer function
)
);

module.exports = registry;
module.exports = registry;
```

2. Use it in a step:

When I am searching for the blue color on Google

3. Retrieve the value in the step implementation:

When('I am searching for the {color} color on Google', async (t, [color]) => {
console.log(color.name); // blue color
});
```js
When('I am searching for the {color} color on Google', async (t, [color]) => {
console.log(color.name); // blue color
});
```

4. Configure the _runner_ to use your custom _ParameterTypeRegistry_:

runner.parameterTypeRegistryFile(require.resolve('./myCustomParamRegistry.js'))
```js
runner.parameterTypeRegistryFile(require.resolve('./myCustomParamRegistry.js'))
```

__Note:__ Do not set `--param-type-registry-file` CLI parameter when running tests through the programming interface as it is internally used to pass the path of the _ParameterTypeRegistry_ file to the gherkin compiler.

Expand Down

0 comments on commit ceb40e2

Please sign in to comment.