Cannot use global plugins with Typescript
See original GitHub issueWhat 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,
},
},
};
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Nuxt Vue Typescript global plugins unavailable inside script ...
The only workaround is to create a function that uses them inside the mixin.ts files and extend them that way. Or import all...
Read more >Plugins - Vue.js
Use global properties scarcely, since it can quickly become confusing if too many global properties injected by different plugins are used throughout an...
Read more >Plugins directory - Nuxt
The plugins directory contains your Javascript plugins that you want to run before instantiating the root Vue.js Application.
Read more >Plugins | Chart.js
inline plugins are not registered. Some plugins require registering, i.e. can't be used inline. const chart = new Chart(ctx, { plugins: ...
Read more >How to create a global custom plugin in Nuxt.js
A global custom plugin can come in handy in a couple of situations. For example, let's imagine that you can't find an open...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
hey @sboudouk hope this https://github.com/codeceptjs/CodeceptJS/pull/3461 will kill the issue.
Thanks for your reply @emanuelwong , but as you mentioned in your quote,
registerGlobal
should be enabled by default iftryTo
is set to enabled, so Typescript theoretically should pick it up, shouldn’t it? 😕