[Question] How to retrieve current test name in jest-circus?
See original GitHub issueI mentioned here how I retrieve the current test name when using the jasmine runner.
Now I’ve updated jest-playwright-preset to 0.2.3 and noted that I’m getting an error:
ReferenceError: jasmine is not defined
I noticed that in the 0.2.0 release the jest-circus became the default runner, which is probably the cause of the error. I’m currently searching for it but I don’t suppose anyone knows how to retrieve the current test name in the jest-circus runner?
For reference, this is how I currently do it:
// jest.setup.js
// save the current test object to a global variable
jasmine.getEnv().addReporter({
specStarted: result => jasmine.currentTest = result,
specDone: result => jasmine.currentTest = result,
});
// my-test.spec.js
// use to check if the current test has errors, if it has, screenshot it
// code before ...
afterEach(async () => {
if (jasmine.currentTest.failedExpectations.length > 0) {
await saveScreenshot(page, fileName, "error");
}
});
// code after ...
// helpers.js
// used for logging somewhere the current test name
// code before...
jasmine.currentTest.fullName
// code after...
So I’m actually using it to do two things:
- check if the current test has any failures
- retrieve the current test name
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Get the current test/spec name in Jest - Stack Overflow
This will return the full path to the test, from the outermost describe to the test itself, separated with ' ' (not the...
Read more >Jest CLI Options
If you run Jest via yarn test , you can pass the command line arguments directly as Jest arguments. Instead of: jest -u...
Read more >How To Test a React App with Jest and React Testing Library
Press `a` to run all tests, or run Jest with `--watchAll`. Watch Usage › Press a to run all tests. › Press f...
Read more >How to install ng-mocks
For any Angular 5+ project you can use the latest version of ng-mocks . ... Simply add the next code to src/test.ts or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@aesyondu Can you share where it’s actually described? I’m trying to use jasmine and keep getting “jasmine is not defined”
Oops I think this is explained in the readme. My bad.