• About
  • Privacy Policy
  • Utilities
Darchuk.NET

Typescript

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

JavaScript–toggling an item in a list with xor

June 1, 2018 by Robert Leave a Comment

I had a problem where I wanted to either remove an item from a list if it existed or add it to the list if it did not exist. A use case for this might be selecting which day(s) of the week you want: Behind the scenes, you might store this as a simple array: … [Read more…]

Posted in: JavaScript, Typescript Tagged: Array, JavaScript, js, list, lodash, toggle, ts, Typescript, xor

C# Mapping an Enum to a key value pair

May 18, 2018 by Robert 2 Comments

Enums are useful because they help you avoid magic numbers.  You can write your code in a way that is easy to read and understand from the human’s perspective, which, at the end of the day, is pretty important. Exposing enums on your Web API I want to share my enums with other things, notably … [Read more…]

Posted in: .NET Core, ASP.NET, C#, Typescript, Web API, Web Development Tagged: .NET, Angular, ASP.NET, C#, enum, Typescript, Web API

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

D3.js, “this”, and TypeScript

February 23, 2018 by Robert Leave a Comment

D3.js is a super cool and very powerful library for creating some really interesting visualizations. One of the problems that I ran into recently was regarding the “this” keyword in D3 functions.  For example, in regular old javascript you would do: Which is fine.  “this” is scoped to the function, so it would point back … [Read more…]

Posted in: D3, JavaScript, Typescript, Web Development Tagged: d3, JavaScript, this, Typescript

Javascript – Combining arrays with the spread operator

February 9, 2018 by Robert Leave a Comment

Recently I had several small arrays in Javascript that I wanted to combine into one array.  It would be easy enough to write a function to accept two arrays, push the values from one into the other, and return the resulting array, but ECMAScript 6 introduced the spread operator (<—a lot more examples in this … [Read more…]

Posted in: JavaScript, Typescript Tagged: JavaScript, Spread, 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