Skip to content

error was thrown in afterAll with angular 5 #79

Closed

Description

@biaggi

I've followed the instructions, but when I execute npm run test, I'm receiving the following error:

> starter-with-testing@0.0.1 test-ci /home/jmgomez/securitas/test/starter-with-testing
> karma start ./test-config/karma.conf.js --single-run


webpack: Compiled successfully.
webpack: Compiling...

webpack: Compiled with warnings.
16 02 2018 15:24:04.909:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/
16 02 2018 15:24:04.910:INFO [launcher]: Launching browser Chrome with unlimited concurrency
16 02 2018 15:24:04.931:INFO [launcher]: Starting browser Chrome
16 02 2018 15:24:05.989:INFO [Chrome 64.0.3282 (Linux 0.0.0)]: Connected on socket 6K6qqAOzO0RIRsN8AAAA with id 89855277
Chrome 64.0.3282 (Linux 0.0.0) ERROR
  {
    "message": "An error was thrown in afterAll\nUncaught TypeError: env.catchExceptions is not a function",
    "str": "An error was thrown in afterAll\nUncaught TypeError: env.catchExceptions is not a function"
  }
Chrome 64.0.3282 (Linux 0.0.0) ERROR
  {
    "message": "An error was thrown in afterAll\nUncaught TypeError: env.catchExceptions is not a function",
    "str": "An error was thrown in afterAll\nUncaught TypeError: env.catchExceptions is not a function"
  }
Chrome 64.0.3282 (Linux 0.0.0): Executed 0 of 0 ERROR (0.004 secs / 0 secs)
Chrome 64.0.3282 (Linux 0.0.0): Executed 0 of 0 ERROR (0.016 secs / 0 secs)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! starter-with-testing@0.0.1 test-ci: `karma start ./test-config/karma.conf.js --single-run`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the starter-with-testing@0.0.1 test-ci script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/jmgomez/.npm/_logs/2018-02-16T14_24_06_588Z-debug.log

Result for ionic info is the following one:

cli packages: (/home/jmgomez/.nvm/versions/node/v8.9.1/lib/node_modules)

    @ionic/cli-utils  : 1.19.1
    ionic (Ionic CLI) : 3.19.1

local packages:

    @ionic/app-scripts : 3.1.8
    Ionic Framework    : ionic-angular 3.9.2

System:

    Node : v8.9.1
    npm  : 5.6.0 
    OS   : Linux 4.4

Misc:

    backend : pro

My android version is 5 instead of 4 as you can check in the package.json uploaded in the repository https://github.com/biaggi/karma-test-failing. Any hint on what's happening there?

Activity

  1. varghese-dev commented on Feb 18, 2018

    @varghese-dev

    @biaggi I was getting similar error and downgrading the jasmine to 2.99 version solved the issue for me.
    "jasmine": "2.99".

    Try it.

  2. biaggi commented on Feb 19, 2018

    @biaggi
    Author

    @varnit-abraham Thank you for your help, but seems that the problem is a different one, the npm list it's already reporting that jasmine's version is 2.99

    npm list
    
    ...
    ├─┬ jasmine@2.99.0
    │ ├── exit@0.1.2
    │ ├── glob@7.1.2 deduped
    │ └── jasmine-core@2.99.1
    ...
    
    
  3. devinshoemaker commented on Feb 24, 2018

    @devinshoemaker

    Thank you @varnit-abraham that seems to have fixed my issues, but do you know why this was causing issues? There must be some breaking change with Jasmine 3.0.0 but I'm not sure what library it's conflicting with.

  4. anibalsanchez commented on Feb 27, 2018

    @anibalsanchez

    Same issue here, and the version downgrade also solved the case:

    npm install --save-dev jasmine@^2.99.0
    
  5. biaggi commented on Feb 27, 2018

    @biaggi
    Author

    You are right... there must be some sort of dependency there that depends directly from jasmine@2.99.0

    It works installing such package. Thank you all and I'm sorry for not trying it before

  6. igcarun07 commented on Mar 2, 2018

    @igcarun07

    @biaggi after install jasmine@2.99.0 it show cannot read property has undefined. Thanks in advance

  7. hyungryuk-zz commented on Mar 8, 2018

    @hyungryuk-zz

    @biaggi i solved it!! after install jasmine@2.99.0, install jasmine-core@^2.99.0 as well! try it

    "jasmine": "^2.99.0",
    "jasmine-core": "^2.99.0",

  8. ChrisGibb commented on Mar 13, 2018

    @ChrisGibb

    Looks like might be a problem with karma-jasmine-html-reporter

    {
        "message": "Uncaught TypeError: env.catchExceptions is not a function\nat node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:24:9\n\nTypeError: env.catchExceptions is not a function\n    at node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:24:9\n    at node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:58:3",
        "str": "Uncaught TypeError: env.catchExceptions is not a function\nat node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:24:9\n\nTypeError: env.catchExceptions is not a function\n    at node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:24:9\n    at node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:58:3"
      }
    
    npm ls --depth=0 | grep jasmine
    
    ├── @types/jasmine@2.8.6
    ├── @types/jasminewd2@2.0.3
    ├── jasmine-core@3.1.0
    ├── jasmine-spec-reporter@4.2.1
    ├── karma-jasmine@1.0.2
    ├── karma-jasmine-diff-reporter@1.1.1
    ├── karma-jasmine-html-reporter@0.2.2
    

    Reverting back fixes the issue

    npm install karma@^2.99
    npm install jasmine-core@^2.99
    
  9. jackrvaughan commented on Mar 30, 2018

    @jackrvaughan

    "jasmine": "^2.99.0",
    "jasmine-core": "^2.99.0"

    Doesn't seem to fix it for me :/

  10. leifwells commented on Mar 30, 2018

    @leifwells
    Contributor
  11. jackrvaughan commented on Apr 2, 2018

    @jackrvaughan

    EDIT: I had an unrelated issue (one of my tests was broken) that was throwing this same error. Sorry!

    Thanks for the reply @leifwells !

    I just noticed that this was an ionic specific thread. I don't use ionic, webpack, or ts-loader; but am hitting this issue all the same.

      "dependencies": {
        "@angular/animations": "^5.1.0",
        "@angular/common": "^5.1.0",
        "@angular/compiler": "^5.1.0",
        "@angular/core": "^5.1.0",
        "@angular/forms": "^5.1.0",
        "@angular/http": "^5.1.0",
        "@angular/platform-browser": "^5.1.0",
        "@angular/platform-browser-dynamic": "^5.1.0",
        "@angular/router": "^5.1.0",
        "core-js": "^2.4.1",
        "raven-js": "^3.22.3",
        "rxjs": "^5.5.6",
        "zone.js": "^0.8.19"
      },
      "devDependencies": {
        "@angular/cli": "^1.7.3",
        "@angular/compiler-cli": "^5.1.0",
        "@angular/language-service": "^5.1.0",
        "@types/jasmine": "~2.5.53",
        "@types/jasminewd2": "~2.0.2",
        "@types/node": "~6.0.60",
        "codelyzer": "~4.0.1",
        "jasmine": "^2.99.0",
        "jasmine-core": "^2.99.0",
        "jasmine-spec-reporter": "~4.1.0",
        "karma": "~2.0.0",
        "karma-chrome-launcher": "~2.1.1",
        "karma-cli": "~1.0.1",
        "karma-coverage-istanbul-reporter": "^1.3.3",
        "karma-jasmine": "^1.1.1",
        "karma-jasmine-html-reporter": "^0.2.2",
        "protractor": "~5.1.2",
        "ts-node": "~3.2.0",
        "tslint": "~5.7.0",
        "typescript": "^2.5.3"
      }
    
  12. jdnav commented on Feb 5, 2019

    @jdnav

    I was facing the same error.
    This combination worked for me in v7:

    ./package.json

    {
    ...
      "dependencies": {
        "@angular/animations": "~7.0.0",
        "@angular/common": "~7.0.0",
        "@angular/compiler": "~7.0.0",
        "@angular/core": "~7.0.0",
        "@angular/forms": "~7.0.0",
        "@angular/http": "~7.0.0",
        "@angular/platform-browser": "~7.0.0",
        "@angular/platform-browser-dynamic": "~7.0.0",
        "@angular/router": "~7.0.0",
        "core-js": "^2.5.4",
        "rxjs": "~6.3.3",
        "zone.js": "~0.8.26"
      },
      "devDependencies": {
        "@angular-devkit/build-angular": "~0.10.0",
        "@angular/cli": "~7.0.4",
        "@angular/compiler-cli": "~7.0.0",
        "@angular/language-service": "~7.0.0",
        "@types/node": "~8.9.4",
        "@types/jasmine": "~2.8.8",
        "@types/jasminewd2": "~2.0.3",
        "codelyzer": "~4.5.0",
        "jasmine-core": "~2.99.1",
        "jasmine-spec-reporter": "~4.2.1",
        "karma": "~3.0.0",
        "karma-chrome-launcher": "~2.2.0",
        "karma-coverage-istanbul-reporter": "~2.0.1",
        "karma-jasmine": "~1.1.2",
        "karma-jasmine-html-reporter": "^0.2.2",
        "protractor": "~5.4.0",
        "ts-node": "~7.0.0",
        "tslint": "~5.11.0",
        "typescript": "~3.1.1"
      }
    }
    
    

    Good luck!

  13. vipinsingh01992 commented on Aug 31, 2019

    @vipinsingh01992

    Facing this issue after doing all:
    An error was thrown in afterAll
    Uncaught TypeError: Cannot read property 'toLowerCase' of undefined thrown

  14. AshuSingh07 commented on Mar 18, 2020

    @AshuSingh07

    I added ts-loader:3.5.0 and typescript: 2.8.4 and it worked for me in Angular 5, ionic 3, Karma 1.71 and jasmine2.99.0 :

    "devDependencies": {
    "@babel/register": "7.8.3",
    "@ionic/app-scripts": "^3.2.3",
    "@types/crypto-js": "3.1.43",
    "@types/es6-promise": "3.3.0",
    "@types/jasmine": "^2.8.6",
    "@types/node": "8.10.45",
    "@types/request-promise": "4.1.45",
    "angular2-template-loader": "0.6.2",
    "es6-template-strings": "2.0.1",
    "html-loader": "0.5.5",
    "ionic-mocks": "1.3.0",
    "istanbul-instrumenter-loader": "3.0.1",
    "jasmine": "2.99.0",
    "jasmine-core": "^2.99.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "1.7.1",
    "karma-chrome-launcher": "2.2.0",
    "karma-coverage-istanbul-reporter": "1.4.3",
    "karma-firefox-launcher": "^1.3.0",
    "karma-jasmine": "1.1.2",
    "karma-jasmine-html-reporter": "0.2.2",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-spec-reporter": "0.0.32",
    "karma-webpack": "2.0.13",
    "ts-loader": "^3.5.0",
    "typescript": "^2.8.4"
    },

  15. Atul-Lohiya commented on Jan 6, 2022

    @Atul-Lohiya

    Seems like angular/karma/jasmine still have this issue. I was using angular 10, jasmine 3.6, karma 5 and still ran into this issue. I did not write the afterAll anywhere and yet this was failing. The reason was async operations that were returning Observable.

    Fix was to pass "done" function parameter to all test cases which were expecting aboe async behaviour and calling "done()" at the end of it something like below.

    it('should not get any data', (done) => { SetupMockActivatedRoute_ParamMap(id, "someParamValue"); SetupDataFetcherService_GetData(id, someOtherParam); component.ngOnInit(); expect(component.data).toBeFalsy(); done(); });

    Here, ngOnInit makes ajax call to get some data. Above test case expects to not get any data and instead show some message to user hence the falsy assertion. I had to to this in all of my test cases where Observable was being used.

    Additionally, there were alot of default generated tests that were not taking care of this. So I cleaned up those to either remove them or fix them like above. And then I fixed all other such cases and now it works everytime in my CICD pipeline.

    So in general if you are getting this error, chances are some mocking is not right or you are not using done() function.

    Also, for reference, read @FDIM's comments at https://github.com/angular/angular/issues/33800.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions