cucumber: Transform should support multiple matches and use World as this context (#25326)

* cucumber: Transform interface supports multiple matches

* cucumber: Use World as this in Transform
This commit is contained in:
Erik Schierboom
2018-04-26 19:27:03 +02:00
committed by Wesley Wigham
parent 8fdc62c1d6
commit 2f6852e993
2 changed files with 21 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ const Status = cucumber.Status;
declare module "cucumber" {
interface World {
visit(url: string, callback: CallbackStepDefinition): void;
toInt(value: string): number;
}
}
@@ -21,6 +22,7 @@ function StepSampleWithoutDefineSupportCode() {
this.visit = (url: string, callback: Callback) => {
callback(null, 'pending');
};
this.toInt = parseInt;
});
Before((scenarioResult: HookScenarioResult, callback: Callback) => {
@@ -164,6 +166,24 @@ function StepSampleWithoutDefineSupportCode() {
useForSnippets: false
});
defineParameterType({
regexp: /(one) (two)/,
transformer: (x, y) => x + y,
name: 'param',
preferForRegexpMatch: false,
useForSnippets: false
});
defineParameterType({
regexp: /123/,
transformer(val) {
return this.toInt(val);
},
name: 'param',
preferForRegexpMatch: false,
useForSnippets: false
});
Given('a {param} step', param => {
assert.equal(param, 'PARTICULAR');
});

View File

@@ -129,7 +129,7 @@ export type GlobalHookCode = (callback?: CallbackStepDefinition) => void;
export interface Transform {
regexp: RegExp;
transformer(arg: string): any;
transformer(this: World, ...arg: string[]): any;
useForSnippets?: boolean;
preferForRegexpMatch?: boolean;
name?: string;