mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 12:42:58 +08:00
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:
committed by
Wesley Wigham
parent
8fdc62c1d6
commit
2f6852e993
@@ -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');
|
||||
});
|
||||
|
||||
2
types/cucumber/index.d.ts
vendored
2
types/cucumber/index.d.ts
vendored
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user