From 2f6852e9934b141c4e4c81396240cc956a56285e Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Thu, 26 Apr 2018 19:27:03 +0200 Subject: [PATCH] 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 --- types/cucumber/cucumber-tests.ts | 20 ++++++++++++++++++++ types/cucumber/index.d.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) 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;