Posts

Showing posts from July, 2024

How to Fake a Route Change in an Angular Unit Test

This isn't something that's come up too often in my experience with Angular, but sometimes I've needed to write code that subscribes to Router.events and takes action based on the current route. But how do you test something like that in a unit test? The key is by using a Subject , which is a kind of Observable , and exposes a next() method, which allows us to simulate a route change. Here's an example:     const event = new NavigationEnd ( 1703 , `/account/orders/ ${ orderId } ` , '/' );     ( router . events as Subject < Event >). next ( event ); By casting Router's events property as a Subject , we can call next() with our NavigationEnd event, and simulate the route change. For the Event type, make sure you are importing Event from @angular/router .

Ranking Led Zeppelin's Studio Albums

Image
The first time I really listened to Led Zeppelin was in my junior year of high school, when my friend John gave me a copy of Led Zeppelin IV  for Christmas. It was one of those rare, consistent albums that I could listen to from start to finish without wanting to skip a track. Not too long after that I picked up Houses of the Holy  and was surprised to find that I liked that  album even more . Sometime after that , I picked up Led Zeppelin II , which I didn't like as much as the other two albums I already had. After high school, I picked up the boxed set . This was my first exposure to a lot of the tracks from the albums I didn't own. One of the things about the boxed set that I heard people say they didn't like was that the tracks were out of chronological order, and it can be kind of confusing as to which song came from which album. A few years later I picked up the second boxed set which included all of the remaining studio tracks not on the first boxed set (pretty cool