```js
const setWorldConstructor = Cucumber.setWorldConstructor
class CustomWorld {
constructor() {
this.agents = new Map()
this.results = new Map()
}
...
}
setWorldConstructor(CustomWorld)
```
Error
```
21 02 2020 15:45:04.232:INFO [karma-server]: Karma v4.4.1 server started at http://0.0.0.0:9876/
21 02 2020 15:45:04.233:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
21 02 2020 15:45:04.237:INFO [launcher]: Starting browser ChromeHeadless
21 02 2020 15:45:04.523:INFO [HeadlessChrome 80.0.3987 (Linux 0.0.0)]: Connected on socket xiRaWk5c4S5uZ0osAAAA with id 64030713
HeadlessChrome 80.0.3987 (Linux 0.0.0) ERROR
Uncaught TypeError: Cannot set property 'World' of undefined
at node_modules/cucumber/dist/cucumber.js:79569:29
TypeError: Cannot set property 'World' of undefined
at setWorldConstructor (node_modules/cucumber/dist/cucumber.js:79569:29)
at test/support/world.js:39:1
npm ERR! Test failed. See above for more details.
```
As mentioned in the other issue all Cucumber functions are globally available in the step files. So no need to import them as the plugin already does that when karma instantiates the cucumber plugin.
Can't seem to set a custom world for my tests - see error at bottom:
dev dependencies:
```js "devDependencies": { "chai": "4.2.0", "cucumber": "6.0.5", "karma": "4.4.1", "karma-chai": "0.1.0", "karma-chrome-launcher": "3.1.0", "karma-cucumber-js-latest": "1.0.5", "karma-mocha": "1.3.0", "mocha": "7.0.1", "puppeteer": "2.1.1" } ```
karma.conf.js:
```js process.env.CHROME_BIN = require('puppeteer').executablePath() module.exports = function(config) { config.set({ frameworks: ["mocha", "chai", "cucumber-js"], browsers: ["ChromeHeadless"], singleRun: true, files: [ "test/**/*.js", ... {pattern: "features/*.feature", included: false} ], plugins: [ "karma-mocha", "karma-chai", "karma-chrome-launcher", "karma-cucumber-js-latest" ] }) } ```
World.js:
```js const setWorldConstructor = Cucumber.setWorldConstructor class CustomWorld { constructor() { this.agents = new Map() this.results = new Map() } ... } setWorldConstructor(CustomWorld) ```
Error
``` 21 02 2020 15:45:04.232:INFO [karma-server]: Karma v4.4.1 server started at http://0.0.0.0:9876/ 21 02 2020 15:45:04.233:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited 21 02 2020 15:45:04.237:INFO [launcher]: Starting browser ChromeHeadless 21 02 2020 15:45:04.523:INFO [HeadlessChrome 80.0.3987 (Linux 0.0.0)]: Connected on socket xiRaWk5c4S5uZ0osAAAA with id 64030713 HeadlessChrome 80.0.3987 (Linux 0.0.0) ERROR Uncaught TypeError: Cannot set property 'World' of undefined at node_modules/cucumber/dist/cucumber.js:79569:29 TypeError: Cannot set property 'World' of undefined at setWorldConstructor (node_modules/cucumber/dist/cucumber.js:79569:29) at test/support/world.js:39:1 npm ERR! Test failed. See above for more details. ```