• About
  • Privacy Policy
  • Utilities
Darchuk.NET

Angular

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

TypeScript async / await

May 4, 2018 by Robert Leave a Comment

JavaScript is pretty dumb.  I know its the most popular language right now (due to the pervasiveness of browsers and other things that can run it), but, I mean, its just… dumb. Luckily TypeScript is pretty awesome.  It takes a lot of what makes JavaScript stupid and fixes it.  It makes it a lot more … [Read more…]

Posted in: Angular, AngularJS, Asynchronous, Concurrency, JavaScript, Typescript, Web Development Tagged: async, await, JavaScript, multi-threaded, promise, single-threaded, threading, threads, Typescript

Angular 2+: Binding HTML Select ngModel to a number

April 20, 2018 by Robert Leave a Comment

I hate magic things.  In programming, I mean.  I try to avoid magic strings and magic numbers as much as possible because I can barely remember the thing I typed five seconds ago, let alone something that you have to maybe type five hours from now.  So, I tend to use a lot of enums … [Read more…]

Posted in: Angular, HTML, Typescript, Web Development Tagged: Angular, HTML, JavaScript, Option, Select, Typescript, Web Development

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

RegExp

December 22, 2017 by Robert Leave a Comment

Regular expressions are powerful, but I find that they’re also incredibly annoying to use. Recently I was trying to create a parser that would try a few different regular expressions and output an object with the proper fields defined.  The input was a string separated by periods, so it was fairly easy to create the … [Read more…]

Posted in: Angular, Typescript, Web Development Tagged: RegEx, RegExp, Regular Expressions, Typescript

Unit testing error paths of Observable

December 8, 2017 by Robert 1 Comment

When you write code against an Observable, you subscribe to the result.  In the subscribe method you provide the callbacks to perform when the Observable is called back.  That means you can execute different code for success and failure. In the last post I wrote about how to mock up and test Observable<T> in Jasmine … [Read more…]

Posted in: Angular, JavaScript, Unit Testing, Web Development Tagged: JavaScript, rxjs, Typescript, unit testing

Unit Testing Angular Observable

December 1, 2017 by Robert 2 Comments

Say that you created a service that essentially wraps Angular’s HttpClient calls: And say that you called that in a component: And now you want to test the Get function to make sure that myValue is set to the value returned by the service.  If you try to create a spy on the function in … [Read more…]

Posted in: Angular, Asynchronous, Jasmine, Unit Testing Tagged: Angular, HttpClient, Jasmine, Observable, Testing, Typescript
« Previous 1 2 3 4 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