CodeceptJS
CodeceptJS copied to clipboard
Cannot use global plugins with Typescript
What are you trying to achieve?
I am trying to use plugins like tryTo
globally in Typescript, however, it seems that they are not defined.
What do you get instead?
Typescript is throwing Cannot find name 'tryTo'.ts(2304)
Scenario('login', ({ I }) => {
tryTo(() => I.amOnPage('/login'); // this fails
I.seeElement({ name: 'login' });
// ...
});
A workaround would be
const tryTo = codeceptjs.container.plugins('tryTo');
Scenario('login', ({ I }) => {
tryTo(() => I.amOnPage('/login'); // this works, but parameters are any
I.seeElement({ name: 'login' });
// ...
});
However, tryTo
then has no type definition (defined as any
). My question would be if it is possible to use plugins like tryTo
globally and with a type definition in Typescript (latter one being more important).
See this Stackblitz as example (note that there are a few more type issues).
Details
- CodeceptJS version:
3.2.1
- NodeJS Version:
14.17.6
- Operating System: MacOS
Configuration file
require('ts-node/register');
exports.config = {
tests: './src/e2e/tests/*_test.ts',
output: './logs/e2e/',
helpers: {
Playwright: {
url: 'https://localhost:8080/',
show: !process.env.HEADLESS,
browser: 'chromium',
},
},
include: {
I: './steps_file.js',
},
bootstrap: null,
mocha: {},
name: 'TS-Test',
plugins: {
pauseOnFail: {},
retryFailedStep: {
enabled: true,
},
tryTo: {
enabled: true,
},
screenshotOnFail: {
enabled: true,
},
},
};
Thanks for your reply @emanuelwong , but as you mentioned in your quote, registerGlobal
should be enabled by default if tryTo
is set to enabled, so Typescript theoretically should pick it up, shouldn't it? 😕
I cannot find any type definitions for the global plugin functions like tryTo
in CodeceptJS's d.ts
files.
any news on this ?
hey @sboudouk hope this https://github.com/codeceptjs/CodeceptJS/pull/3461 will kill the issue.
Thanks @PeterNgTr , will look forward to this.