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

TypeError: Cannot set property 'World' of undefined #1

Open
llorllale opened this issue Feb 21, 2020 · 1 comment
Open

TypeError: Cannot set property 'World' of undefined #1

llorllale opened this issue Feb 21, 2020 · 1 comment

Comments

@llorllale
Copy link

llorllale commented Feb 21, 2020

Can't seem to set a custom world for my tests - see error at bottom:

dev dependencies:

  "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:

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:

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.

@mitcoding
Copy link
Owner

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.

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

No branches or pull requests

2 participants