Search code examples
angularjasminekarma-jasmine

Jasmine Karma afterall hides property error


I am running ng test and getting the following error

An error was thrown in afterAll TypeError: Cannot read properties of undefined (reading 'hide') at SafeSubscriber._next (http://localhost:9876/karma_webpack/webpack:/src/app/admin/admin-appdetails/admin-appdetails.component.ts:676:8) at SafeSubscriber.__tryOrUnsub (http://localhost:9876/karma_webpack/webpack:/node_modules/rxjs/_esm2015/internal/Subscriber.js:183:1) at SafeSubscriber.next (http://localhost:9876/karma_webpack/webpack:/node_modules/rxjs/_esm2015/internal/Subscriber.js:122:1) at Subscriber._next (http://localhost:9876/karma_webpack/webpack:/node_modules/rxjs/_esm2015/internal/Subscriber.js:72:1) at Subscriber.next (http://localhost:9876/karma_webpack/webpack:/node_modules/rxjs/_esm2015/internal/Subscriber.js:49:1) at Observable._subscribe (http://localhost:9876/karma_webpack/webpack:/node_modules/rxjs/_esm2015/internal/util/subscribeToArray.js:3:1) at Observable._trySubscribe (http://localhost:9876/karma_webpack/webpack:/node_modules/rxjs/_esm2015/internal/Observable.js:42:1) at Observable.subscribe (http://localhost:9876/karma_webpack/webpack:/node_modules/rxjs/_esm2015/internal/Observable.js:28:1) at AdminAppdetailsComponent.onBlockUnblockStatus (http://localhost:9876/karma_webpack/webpack:/src/app/admin/admin-appdetails/admin-appdetails.component.ts:673:8) at UserContext. (http://localhost:9876/karma_webpack/webpack:/src/app/admin/admin-appdetails/admin-appdetailsChrome 104.0.5112.81 (Windows 10) ERROR An error was thrown in afterAll TypeError: Cannot read properties of undefined (reading 'hide') at SafeSubscriber._next (http://localhost:9876/karma_webpack/webpack:/src/app/admin/admin-appdetails/admin-appdetails.component.ts:676:8) at SafeSubscriber.__tryOrUnsub (http://localhost:9876/karma_webpack/webpack:/node_modules/rxjs/_esm2015/internal/Subscriber.js:183:1) at SafeSubscriber.next (http://localhost:9876/karma_webpack/webpack:/node_modules/rxjs/_esm2015/internal/Subscriber.js:122:1)

**admin-appdetails.component.ts**

https://wtools.io/paste-code/bEu3

admin-appdetails.components.spec.ts https://wtools.io/paste-code/bEu4

These are the files

Unable to detect why this error is coming.

Thanks


Solution

  • If you check the stacktrace, you can clearly see the problem is in admin-appdetails.component.ts:676:8 check for the hide property and fix it!

    An error was thrown in afterAll TypeError: Cannot read properties of undefined (reading 'hide') at SafeSubscriber._next (http://localhost:9876/karma_webpack/webpack:/src/app/admin/admin-appdetails/admin-appdetails.component.ts:676:8) at SafeSubscriber.__tryOrUnsub
    

    Mock the property in all test cases and it worked.