question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mocha TypeError when running test

See original GitHub issue

What are you trying to achieve?

Run test with : npx codeceptjs run search_test.js

What do you get instead?

Provide console output if related. Use --verbose mode for more details.

TypeError: Cannot set property id of #<Test> which has only a getter
    at /home/gil/dev/heig/amt/OverFlow/e2e/node_modules/codeceptjs/lib/mochaFactory.js:53:46
    at Array.forEach (<anonymous>)
    at Suite.eachTest (/home/gil/dev/heig/amt/OverFlow/e2e/node_modules/mocha/lib/suite.js:438:14)
    at /home/gil/dev/heig/amt/OverFlow/e2e/node_modules/mocha/lib/suite.js:440:11
    at Array.forEach (<anonymous>)
    at Suite.eachTest (/home/gil/dev/heig/amt/OverFlow/e2e/node_modules/mocha/lib/suite.js:439:15)
    at Mocha.mocha.loadFiles (/home/gil/dev/heig/amt/OverFlow/e2e/node_modules/codeceptjs/lib/mochaFactory.js:53:21)
    at Mocha.run (/home/gil/dev/heig/amt/OverFlow/e2e/node_modules/mocha/lib/mocha.js:970:10)
    at /home/gil/dev/heig/amt/OverFlow/e2e/node_modules/codeceptjs/lib/codecept.js:170:15
    at new Promise (<anonymous>)

Cannot set property id of #<Test> which has only a getter

TypeError: 
    at /home/gil/dev/heig/amt/OverFlow/e2e/node_modules/codeceptjs/lib/mochaFactory.js:53:46
    at Array.forEach (<anonymous>)
    at Suite.eachTest (/home/gil/dev/heig/amt/OverFlow/e2e/node_modules/mocha/lib/suite.js:438:14)
    at /home/gil/dev/heig/amt/OverFlow/e2e/node_modules/mocha/lib/suite.js:440:11
    at Array.forEach (<anonymous>)
    at Suite.eachTest (/home/gil/dev/heig/amt/OverFlow/e2e/node_modules/mocha/lib/suite.js:439:15)
    at Mocha.mocha.loadFiles (/home/gil/dev/heig/amt/OverFlow/e2e/node_modules/codeceptjs/lib/mochaFactory.js:53:21)
    at Mocha.run (/home/gil/dev/heig/amt/OverFlow/e2e/node_modules/mocha/lib/mocha.js:970:10)
    at /home/gil/dev/heig/amt/OverFlow/e2e/node_modules/codeceptjs/lib/codecept.js:170:15
    at new Promise (<anonymous>)

Provide test source code if related

Content of search_test.js:

Feature('search');

Scenario('test search title', ({ I }) => {
    I.amOnPage('/')
    I.fillField('s', 'question 2')
    I.click('Search')
    I.see('Question 2')
    I.see('Contenu 2')
    I.dontSee('Question 1')
    I.dontSee('Contenu 1')
    I.dontSee('Question 3')
    I.dontSee('Contenu 3')
});

Scenario('test search author', ({ I }) => {
    I.amOnPage('/')
    I.fillField('s', 'gil')
    I.click('Search')
    I.see('Question 1')
    I.see('Contenu 1')
    I.dontSee('Question 2')
    I.dontSee('Contenu 2')
    I.dontSee('Question 3')
    I.dontSee('Contenu 3')
});

Details

  • CodeceptJS version: 3.0.0
  • NodeJS Version: 12.18.4
  • Operating System: Manjaro Linux
  • Using Playwright 1.5.1
Configuration file
const { setHeadlessWhen } = require('@codeceptjs/configure');

// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

exports.config = {
  tests: './*_test.js',
  output: './output',
  helpers: {
    Playwright: {
      url: 'http://localhost:9080/overflow',
      show: true,
      browser: 'chromium'
    }
  },
  include: {
    I: './steps_file.js'
  },
  bootstrap: null,
  mocha: {},
  name: 'e2e',
  translation: 'fr-FR',
  plugins: {
    pauseOnFail: {},
    retryFailedStep: {
      enabled: true
    },
    tryTo: {
      enabled: true
    },
    screenshotOnFail: {
      enabled: true
    }
  }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

5reactions
lukythcommented, Oct 19, 2020

I have this same error as well, with the project that I just setup an hour ago. I fixed this by adding mocha to package.json as well, with the version pin to "mocha": "8.1.3",. I think this is more likely an issue from mocha@8.2.0, which was released 3 days ago https://github.com/mochajs/mocha/releases/tag/v8.2.0.

1reaction
balsigergilcommented, Oct 20, 2020

Quick fix

Open your package.json and specify explicitly the version 8.1.3 of Mocha :

{
    "name": "codeceptjs-tests",
    "version": "0.1.0",
    "private": true,
    "scripts": {
        "codeceptjs": "codeceptjs run --steps",
        "codeceptjs:headless": "HEADLESS=true codeceptjs run --steps",
        "codeceptjs:ui": "codecept-ui --app"
    },
    "devDependencies": {
        "@codeceptjs/configure": "^0.6.0",
        "@codeceptjs/examples": "^1.2.1",
        "@codeceptjs/ui": "^0.4.1",
        "codeceptjs": "^3.0.0",
        "playwright": "^1.5.1",
        "mocha": "8.1.3"
    }
}

Apparently the bug occurs with the Mocha 8.2.0 update. This should temporarily fix the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocha Unit Testing: Uncaught TypeError: Cannot read ...
I get the error Uncaught TypeError: Cannot read property 'apply' of undefined . let chai = require('chai') let chaiHttp = require('chai- ...
Read more >
Getting error when I run my test using mocha
When I run this using node 'filename' it is running fine with no issue. When I run using mocha node_modules/mocha/bin/mocha 'filename' I am ......
Read more >
mochajs/mocha - Gitter
What is the suggested way to run mocha units tests with 'debugger' in the test code? ... I get a Type error: timeout...
Read more >
Mocha documentation — DevDocs
When a test file is loaded, Mocha executes all of its suites and finds–but does not execute–any hooks and tests therein. Top-level hooks,...
Read more >
Failed to run mocha tests if mocha configured to ... - YouTrack
Create a test using a mocha test runner · Run the test via IDE using the following options parallel: true or --parallel CLI...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found