jest-allure icon indicating copy to clipboard operation
jest-allure copied to clipboard

TypeError: Cannot set property 'currentTest' of undefined

Open jeremyhiggs opened this issue 5 years ago • 4 comments

When running jest with jest-allure installed, I often receive the above error. This did not use to happen, before using jest-allure.

Extended error message:

UserPreferences › can create an instance of the model from an arbitrary mock

TypeError: Cannot set property 'currentTest' of undefined

  at Allure.Object.<anonymous>.Allure.startCase (node_modules/allure-js-commons/index.js:44:23)
  at JasmineAllureReporter.specStarted (node_modules/jest-allure/dist/setup.js:24:21)

Package versions:

"jest": "^24.9.0",
"jest-allure": "^0.1.1",

Jest config (in package.json):

  "jest": {
    "collectCoverage": true,
    "coverageDirectory": "coverage",
    "preset": "jest-expo",
    "reporters": [
      "default"
    ],
    "setupFilesAfterEnv": [
      "jest-allure/dist/setup"
    ]
  }

I added a few console logs in jest-aalure/dist/setup.js:

FAIL models/tests/UserPreferences.test.js (98.219s) ● Console

console.error node_modules/jest-allure/dist/setup.js:23
  specStarted = skip NeedMock dummy
console.error node_modules/jest-allure/dist/setup.js:14
  startSuite = UserPreferences
console.error node_modules/jest-allure/dist/setup.js:23
  specStarted = can create an instance of the model from an arbitrary mock

It seems that startSuite is being called after specStarted, which would explain why Allure.startCase cannot find the suite. Any idea why this would be happening?

jeremyhiggs avatar Nov 16 '19 09:11 jeremyhiggs

Any update on this ? Am having the same issue

arunp-motorq avatar Feb 19 '20 20:02 arunp-motorq

Having the same issue

That happens when you use some reporters methods in before/beforeAll hooks. Jest-allure considers test is not started, so nothing to attach to:

before(()=> {
    reporter.addAttachment(`attach name`, JSON.stringify({
                hello: "world"
            }, null, 2), 'application/json')
})

Xotabu4 avatar Aug 10 '20 17:08 Xotabu4

Same as #6

Xotabu4 avatar Aug 11 '20 08:08 Xotabu4

For us the case was in an odd test which had no parent describe block. Wrapping it with one solved the issue

ma-nk avatar Jan 30 '23 13:01 ma-nk