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.

[Question] How to retrieve current test name in jest-circus?

See original GitHub issue

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

  1. check if the current test has any failures
  2. retrieve the current test name

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hananmalkacommented, Jan 17, 2021

@aesyondu Can you share where it’s actually described? I’m trying to use jasmine and keep getting “jasmine is not defined”

1reaction
aesyonducommented, Jun 8, 2020

Oops I think this is explained in the readme. My bad.

Read more comments on GitHub >

github_iconTop 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 >
jest-circus | Yarn - Package Manager
jest -circus. The next-gen test runner for Jest ...
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 >

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