-
Notifications
You must be signed in to change notification settings - Fork 672
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
Document how to write TypeScript custom actions #7870
Comments
Hi @DanKaplanSES, There is an instruction on how to use TypeScript with Custom Actions and an example: https://testcafe.io/documentation/404150/guides/advanced-guides/custom-test-actions#use-custom-actions-with-typescript |
Thanks @Aleksey28 The existing documentation details how to define TypeScript types for your custom actions, but I would like to write my implementation in TypeScript, too. This is the first example on that page: module.exports = {
customActions: {
async makeCoffee (args) {
await this.click(args);
},
}
}; I'm requesting documentation that shows how to write this as TypeScript code instead. It would probably end up looking something like this: import { TestCafeConfigurationOptions } from 'testcafe'; // Unfortunately this doesn't compile because this type is not exported
const myTestcafeConfig: TestCafeConfigurationOptions = {
customActions: { // NOTE: customActions doesn't exist on TestCafeConfigurationOptions, so it would need to be added
async makeCoffee(args: string[]) {
await this.click(args);
},
},
};
export default myTestcafeConfig; |
The TestCafe configuration file supports only Also, note that the interface for custom action is defined in the global scope, not in //definitions.d.ts
import 'testcafe';
declare global {
interface CustomActions {
makeCoffee: (selector: Selector | string) => TestControllerPromise
}
} //.testcaferc.js
module.exports = {
src: ["definitions.d.ts", "test.js"],
browsers: 'crhome',
customActions: {
async makeCoffee(args) {
await this.click(args);
},
}
}; //test.ts
fixture`Test cookies`
.page`./index.html`;
test('Test with a custom action', async (t: TestController) => {
await t.click('#btn-prepare-machine')
.customActions.makeCoffee('#btn-coffee')
.click('#btn-clean-machine');
}) |
What is your Scenario?
This is a continuation of #7337: The existing documentation details how to define TypeScript types for your custom actions, but I would like to write my implementation in TypeScript, too.
The custom action I want to write is pretty sophisticated, and being able to type check my code would reduce my troubleshooting effort.
What are you suggesting?
Can the documentation include an example of how to write a TypeScript definition of a custom action?
What alternatives have you considered?
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: