diff --git a/types/cucumber/cucumber-tests.ts b/types/cucumber/cucumber-tests.ts index b7fa675095..41a52c6d61 100644 --- a/types/cucumber/cucumber-tests.ts +++ b/types/cucumber/cucumber-tests.ts @@ -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'); }); diff --git a/types/cucumber/index.d.ts b/types/cucumber/index.d.ts index 03dda3d736..8cfed3ef31 100644 --- a/types/cucumber/index.d.ts +++ b/types/cucumber/index.d.ts @@ -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;