angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

`stopSpecOnExpectationFailure` Jasmine configuration option does not work

Open johnnygerard opened this issue 1 year ago • 0 comments

Command

test

Is this a regression?

  • [ ] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

stopSpecOnExpectationFailure option should stop spec execution at the first failed expectation.

Adding this option in jasmine.json with Jasmine 5.1.0 works.

The same option does not work with Angular when adding the option in karma.conf.js.

Minimal Reproduction

ng new app --defaults
cd app
ng g config karma

Add stopSpecOnExpectationFailure: true to the config object in client.jasmine:

    client: {
      jasmine: {
        // you can add configuration options for Jasmine here
        // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
        // for example, you can disable the random execution with `random: false`
        // or set a specific seed with `seed: 4321`
        stopSpecOnExpectationFailure: true,
        random: false
      },
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },

Note: I added random: false as well to make sure that the issue is option-specific.

Add a spec with a failing expectation:

describe('Test', () => {
  it('1', () => {
    expect(true).toBe(false);
    console.log('This should not be logged!');
  });
});

Finally run ng test and check the logs.

Exception or Error

$ ng test
✔ Browser application bundle generation complete.
17 01 2024 15:49:46.973:WARN [karma]: No captured browser, open http://localhost:9876/
17 01 2024 15:49:46.984:INFO [karma-server]: Karma v6.4.2 server started at http://localhost:9876/
17 01 2024 15:49:46.984:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
17 01 2024 15:49:46.986:INFO [launcher]: Starting browser Chrome
17 01 2024 15:49:47.420:INFO [Chrome 120.0.0.0 (Linux x86_64)]: Connected on socket vIUN7dZWUgtUsMChAAAB with id 69461604
LOG: 'This should not be logged!'
Chrome 120.0.0.0 (Linux x86_64): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
Chrome 120.0.0.0 (Linux x86_64) Test 1 FAILED
        Expected true to be false.
            at <Jasmine>
            at UserContext.apply (src/app/app.component.spec.ts:3:18)
            at _ZoneDelegate.invoke (node_modules/zone.js/fesm2015/zone.js:368:26)
            at ProxyZoneSpec.onInvoke (node_modules/zone.js/fesm2015/zone-testing.js:273:39)
            at _ZoneDelegate.invoke (node_modules/zone.js/fesm2015/zone.js:367:52)
Chrome 120.0.0.0 (Linux x86_64): Executed 1 of 1 (1 FAILED) (0.014 secs / 0.003 secs)
TOTAL: 1 FAILED, 0 SUCCESS

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 17.0.10
Node: 18.19.0
Package Manager: npm 10.3.0
OS: linux x64

Angular: 17.0.9
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.10
@angular-devkit/build-angular   17.0.10
@angular-devkit/core            17.0.10
@angular-devkit/schematics      17.0.10
@angular/cli                    17.0.10
@schematics/angular             17.0.10
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.3

Anything else relevant?

No response

johnnygerard avatar Jan 17 '24 14:01 johnnygerard