Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to define custom function context types to extend the default World #867

Closed
wants to merge 1 commit into from

Conversation

moretti
Copy link

@moretti moretti commented Oct 27, 2022

Following the discussion on #864, I updated the type definition to make the step definition function context type extendable, e.g.:

import { Given } from "@badeball/cypress-cucumber-preprocessor";

interface CustomWorld extends Mocha.Context {
  homepage: HomePageDriver;
}

Given("I'm on the homepage", function (this: CustomWorld) {
  cy.visit("/");
  this.homepage = new HomePageDriver(cy);
});

@badeball
Copy link
Owner

Can you add a test case showing the new functionality? Such test should not pass before the implementation is introduced and pass thereafter. https://github.com/badeball/cypress-cucumber-preprocessor/blob/master/lib/index.test-d.ts

@moretti moretti force-pushed the typescript-context branch from e6c71d9 to 56daf44 Compare October 31, 2022 07:56
@moretti
Copy link
Author

moretti commented Oct 31, 2022

@badeball thank you for your feedback. I added more type tests here:

interface CustomWorld extends Mocha.Context {
pageDriver: {
navigateTo(url: string): void;
};
}
Given(/foo/, function (this: CustomWorld, url: string) {
expectType<CustomWorld>(this);
this.pageDriver.navigateTo(url);
});
When(/foo/, function (this: CustomWorld, url: string) {
expectType<CustomWorld>(this);
this.pageDriver.navigateTo(url);
});
Then(/foo/, function (this: CustomWorld, url: string) {
expectType<CustomWorld>(this);
this.pageDriver.navigateTo(url);
});

@badeball
Copy link
Owner

badeball commented Nov 7, 2022

Thanks for your contribution! I've merged this with 31aa9a0 and it's released as v13.1.0.

@badeball badeball closed this Nov 7, 2022
@moretti moretti deleted the typescript-context branch November 15, 2022 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants