3

We have an Angular 10 application with about 600 Jasmine tests run in Karma using headless Chrome.

Recently one of these tests started failing with an "An error was thrown in beforeEach" error. What is the best way to find out which test is failing?

I tried adding some reporters to the Karma configuration, so that I would see which tests are being executed. The reporter I tried printed the name of every tests after it was executed, but since the test failed in a beforeEach method, the name never got printed. I tried looking for a reporter that would print the name of a test before it was executed, but I could not find any. Eventually I did a binary search by deleting half the test suite until I figured out which test was failing, but I believe there must be a better way to do this.

Minop
  • 386
  • 4
  • 13
  • Check this out:- https://stackoverflow.com/a/18168335/1289713 – Vimal Patel Jul 10 '21 at 06:41
  • This happened to me recently as well and I used this reporter https://www.npmjs.com/package/karma-spec-reporter which tells you which test is running and whether it passed or failed (the full text). The posts here can help you as well. https://stackoverflow.com/a/37703380/7365461 You can also follow this guide https://morioh.com/p/c96gCsCT3GlE and it has a picture of how the output will look like. – AliF50 Jul 10 '21 at 13:31

1 Answers1

-1

You can edit the message in it block of each test case and monitor it on karma console.In this case it's "should create"

it("should create", () => {
    expect(component).toBeTruthy();
  });

If you're running too many test cases use f and x on describe as well as it block.

fdescribe - Karma will only run the test cases for the components in which fdescribe is written.

xdescribe - Karma will skip the test cases for the components in which fdescribe is written

Similarly you can use this prefix for individual test case (it block). This will be helpful if you'll have to run only one or few test cases or skip few test cases.

fit - Karma will only run the test cases for the components in which fit is written.

xit - Karma will only skip the test cases for the components in which xit is written.

Kartik Dolas
  • 703
  • 1
  • 9
  • 24