• About
  • Privacy Policy
  • Utilities
Darchuk.NET

Jasmine

[object ErrorEvent] thrown … again

March 8, 2019 by Robert Leave a Comment

So there I am, happily writing unit tests, and suddenly this appears I keep seeing this error while trying to write Angular tests.  I… *think* this happens when something goes wrong during the constructor of a component.  I’ve written before about how it could be due to an @Input property not being initialized properly. But, … [Read more…]

Posted in: Angular, Jasmine, JavaScript, Typescript, Unit Testing Tagged: Angular, Jasmine, JavaScript, Testing, Typescript, UnitTesting

Angular Unit Testing–Cannot read property ‘ngInjectableDef’ of undefined

October 5, 2018 by Robert 12 Comments

Recently, I was writing some unit tests for Angular.    It was a pretty basic test, just checking to see if a method on an injected provider was called when a method in my component executed… but suddenly everything blew up with this weird error: TypeError: Cannot read property ‘ngInjectableDef’ of undefined Googling around didn’t really … [Read more…]

Posted in: Angular, Jasmine, JavaScript, Typescript, Unit Testing Tagged: Angular, Jasmine, Testing, Typescript, unit testing

Jasmine–Setting the clock and deferring assertions

September 21, 2018 by Robert Leave a Comment

Sometimes when you’re writing Javascript unit tests you have to give Javascript a chance to catch up before checking your assertions.  Javascript uses a single event loop, so it isn’t multi-threaded in the same way as other languages.  You can still get a “multi-threaded feel” by using callbacks (promises, observables, etc), but at the end … [Read more…]

Posted in: Asynchronous, Jasmine, JavaScript, Typescript, Unit Testing, Web Development Tagged: Asynchronous, Jasmine, JavaScript, Testing, Typescript, unit testing

Jasmine–Testing code that contains setTimeout

September 14, 2018 by Robert Leave a Comment

Recently I wrote some code that contained a setTimeout.  The reason was so that the UI could catch up before the function actually fired – something that I’ve found the need to do with javascript from time to time. So, when it comes to testing the code… my test just skipped along until it literally … [Read more…]

Posted in: Angular, Asynchronous, Concurrency, Jasmine, JavaScript, Typescript, Unit Testing, Web Development Tagged: Angular, async, Jasmine, setTimeout, Testing, Typescript, unit testing

Testing Observables in Angular >= 6.0.0

August 17, 2018 by Robert Leave a Comment

In a previous post I talked about testing Observables in your Angular code.  This is pretty common, because HttpClient sends back an Observable<T> – so if you want to spyOn that function, you’ll need to figure out how to return an Observable. I’ve been bouncing around a couple of projects/repos recently, and it turns out … [Read more…]

Posted in: Angular, Asynchronous, Jasmine, Typescript, Unit Testing Tagged: Angular, Jasmine, Observable, rxjs, Testing, Typescript, unit testing

Jasmine–Async callback was not invoked within timeout

August 10, 2018 by Robert Leave a Comment

Recently I was updating and fixing some existing unit tests after doing a (rather large) overhaul of code.The unit test previously needed to wait for an asynchronous callback to finish before continuing, something like this: Note the optional done parameter provided to beforeEach.  This is a void function that signals Jasmine that the callback is … [Read more…]

Posted in: Angular, Asynchronous, Concurrency, Jasmine, JavaScript, Typescript, Web Development Tagged: async, Asynchronous, beforeEach, Callback, Jasmine, specified, test, Testing, timeout, unit testing

TypeScript unit testing–Checking to see if the values of two arrays are equal

August 3, 2018 by Robert Leave a Comment

In Jasmine, you can expect an object toBe another object. However, this will check to see if the two arrays point to the same reference object.  In other words, it will check to see if the arrays point to the same memory address. Produces this not-very-helpful error message: Expected [ 42, ‘Forty-Two’ ] to be … [Read more…]

Posted in: Angular, Jasmine, Typescript, Unit Testing, Web Development Tagged: Jasmine, Karma, Testing, toBe, toEqual, Typescript, unit testing

Unit Testing Angular–initializing an object in ngOnInit

July 27, 2018 by Robert Leave a Comment

Recently I had a problem where in an Angular unit test where I had an object that was being initialized in ngOnInit from a service.  As far as I could tell, everything should be working, but the test would fail because I was trying to set a property on the object before it had finished … [Read more…]

Posted in: Angular, Debugging, Jasmine, Typescript, Unit Testing, Web Development Tagged: Angular, Jasmine, Karma, ngOnInit, Testing, Typescript, unit testing

Karma / Jasmine Unit Test Cheat Sheet

June 8, 2018 by Robert Leave a Comment

I find that writing unit tests in JavaScript kind of sucks, so this post will (hopefully) serve as a cheat sheet of all the stuff I keep looking up.  As such, it will be updated as I learn new stuffs. How To: scope test run to specific tests Remember to set it back before you … [Read more…]

Posted in: Angular, AngularJS, Jasmine, JavaScript, Typescript, Unit Testing, Web Development Tagged: Cheatsheet, Guide, Jasmine, JavaScript, js, Karma, Testing, ts, Typescript, unit testing

Angular testing–[object ErrorEvent] thrown

December 29, 2017 by Robert 2 Comments

I was trying to be good and keep up with my Karma unit tests in my Angular 5 Typescript project, but I was running in to a really weird error that left a lot to be desired: The logs in the console window are not helpful either… Chrome 63.0.3239 (Windows 10 0.0.0) ERROR   Uncaught NetworkError: … [Read more…]

Posted in: Angular, Jasmine, Unit Testing Tagged: Angular, ErrorEvent, Jasmine, Karma, Unit Test
1 2 Next »

Recent Posts

  • Allowing trailing JSON commas in ASP.NET Core 3
  • YADNC3JSG–Yet Another .NET Core 3.0 JSON Serializer Gotcha
  • Logging in a .NET Core 3 SignalR client
  • .NET Core 3 unit testing project sdk
  • .NET Core 3.0 Upgrade–New JSON Serializer Gotchas

Recent Comments

  1. Robert on C# Setting Socket Keep-Alive
  2. Oliver Schramm on C# Setting Socket Keep-Alive
  3. John Anderson on Waiting for a keypress asynchronously in a C# console app
  4. Ronald Garlit on .NET Core 3 unit testing project sdk
  5. Ronald Garlit on .NET Core 3 unit testing project sdk

Copyright © 2025 Darchuk.NET.

Omega WordPress Theme by ThemeHall