Updated signature of setDefinitionFunctionWrapper (#36709)

* Fixes to definition cucumber wrapper

* Add types

* Oops
This commit is contained in:
Don Jayamanne 2019-07-15 09:53:27 -07:00 committed by Andrew Branch
parent 54f17bc05e
commit 35bd091687
2 changed files with 20 additions and 2 deletions

View File

@ -1,5 +1,5 @@
import * as assert from "power-assert";
import { setWorldConstructor, defineParameterType, After, AfterAll, Before, BeforeAll, Given, When, Then } from "cucumber";
import { setDefinitionFunctionWrapper, setWorldConstructor, defineParameterType, After, AfterAll, Before, BeforeAll, Given, When, Then } from "cucumber";
import cucumber = require("cucumber");
type Callback = cucumber.CallbackStepDefinition;
@ -187,6 +187,22 @@ function StepSampleWithoutDefineSupportCode() {
Given('a {param} step', param => {
assert.equal(param, 'PARTICULAR');
});
Given('a step with custom options for function wrapper', { timeout: 1, wrapperOptions: { retry: 2 } }, param => {
console.log('Mock step');
});
Given('a step with custom options for function wrapper with any complext wrapper options', { wrapperOptions: { moreOptions: { nested: [] } } }, param => {
console.log('Mock step');
});
setDefinitionFunctionWrapper((fn: () => void) => {
return fn;
});
setDefinitionFunctionWrapper((fn: () => void, options: {}) => {
console.log(`Custom Options passed into step`);
return fn;
});
}
// syntax defineSupportCode deprecated

View File

@ -6,6 +6,7 @@
// BendingBender <https://github.com/BendingBender>
// ErikSchierboom <https://github.com/ErikSchierboom>
// Peter Morlion <https://github.com/petermorlion>
// Don Jayamanne <https://github.com/DonJayamanne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
@ -45,6 +46,7 @@ export type StepDefinitionCode = (this: World, ...stepArgs: any[]) => any;
export interface StepDefinitionOptions {
timeout?: number;
wrapperOptions?: {[key: string]: any};
}
export interface StepDefinitions {
@ -73,7 +75,7 @@ export function defineStep(pattern: RegExp | string, options: StepDefinitionOpti
export function Given(pattern: RegExp | string, code: StepDefinitionCode): void;
export function Given(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void;
export function setDefaultTimeout(time: number): void;
export function setDefinitionFunctionWrapper(fn: () => void, options?: {[key: string]: any}): void;
export function setDefinitionFunctionWrapper(fn: ((fn: () => void) => (...args: any[]) => any) | ((fn: () => void, options?: {[key: string]: any}) => (...args: any[]) => any)): void;
// tslint:disable-next-line ban-types
export function setWorldConstructor(world: ((this: World, init: {attach: Function, parameters: {[key: string]: any}}) => void) | {}): void;
export function Then(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void;