jest-allure
jest-allure copied to clipboard
TypeError: Cannot set property 'currentTest' of undefined
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?
Any update on this ? Am having the same issue
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')
})
Same as #6
For us the case was in an odd test which had no parent describe
block. Wrapping it with one solved the issue