Posts

Mocking httpResource in Angular

httpResource  is still experimental in Angular, and I've begun playing around with it. Once I got a working implementation on a simple form, I wanted to update my tests. This was challenging. I did some searching and found a couple of posts about using HttpTestingController  and mocking a response, but I wanted to retain the service-level abstraction in my component unit tests, which know nothing about HTTP, only that services are used, and one of them now returns an HttpResourceRef in place of an Observable. Here's the mock implementation I wrote. I'm using Vitest now in this project instead of Jasmine, but the syntax should hopefully still make sense. class ExerciseServiceMock {   get = vi . fn (). mockImplementation (() => {       const paginatedResults = new PaginatedResults < ExerciseDTO >();       paginatedResults . totalCount = 0 ;       paginatedResults . results = new Array < ExerciseDTO >(...

The 10 Lowest Rated Movies on My NAS

Image
One of my hobbies for a long time now has been the building of a digital library of movies and TV shows. I originally undertook this using media stored on a combination of USB drives and a DLNA server, but just over a year ago purchased a NAS and hosted an instance of Jellyfin . Jellyfin is amazing and I plan to write a separate entry about that later. Today, out of curiosity, I decided to see if it were possible to sort my media in order of how well it was rated (community rating/general consensus), and yes, Jellyfin provides this. And once I'd sorted my movies in order of community rating, I just had to know: What's the worst rated stuff I have here? What follows is that list, in descending order -- my "Bottom 10 Movies", so to speak. #10 - Can't Stop The Music Starring Steve Guttenberg and The Village People Is It Really That Bad?  Yes Okay, okay, I need to make something clear at the outset: I love bad movies. And this one is...woof. Bad. It's bad. It...

Roku OS 15.0.4 Breaks HEVC Decoding

One of my hobbies is building my own streaming video library. I've been meaning to blog about it for awhile. Unfortunately, my intro to doing so is this . Last week, Roku OS 15.0.4 found its way onto my Roku TV and Roku Ultra 4800R. And while the TV took it fine, the Ultra did not . Playback of HEVC video is now hampered by pixelation and freezing. I wasn't sure if the Roku OS update was the culprit, or if it was the Jellyfin client for Roku that I use to stream videos from my Jellyfin server. But putting one of the (now) problematic videos onto a USB drive and playing it via Roku's own Media Player resulted in the same problem. I found my way to the Roku community forums where the most recently updated post was about this happening when using the Plex  app. As of today, that post is 17 days old. The response from Roku support has been...lacking. Very lacking. "It's under investigation." I left a comment mentioning this was unrelated to Plex and relayed my USB...

Drew

Image
  I guess I should begin this by saying I'm not on Facebook. I used to be, but stopped using it at a time which was, in hindsight, probably a good time to leave. But I'd been a Facebook user for years prior, and the last person I had contact with there before deactivating my account was Drew Rusin. I'd met Drew years ago, at a pool hall in Langhorne called The Rack Room . Years later, it's where I met up with him for the last time. The Rack Room was, by that time, closed, and we met up there to grab a bite and catch up at the Denny's which was out front. Back in the day, I'd met Drew through Dave Tyson, who also used to hang out at the pool hall with Drew and another friend, Jay Winslow. Dave, Drew, and Jay were almost always together. They were a few years younger than me. The Rack Room  was kind of like Cheers : maybe not everybody  knew your name, but enough people to make you feel at home I guess. It sounds corny. Regardless, I spent a lot of time there wit...

My 10 Favorite Christmas Songs

With the Christmas season upon us once again , I wanted to write about some of my favorite Christmas songs. As an adult, I've found it difficult to get into the holiday spirit each year because there's always a lot happening. As a kid, the world almost seems to stop as the holidays approach and arrive, but as an adult, things just keep on moving. One of the few things that has any affect on my mood during this time is the music, almost always because of some sort of nostalgia, and even then, there are times when it does nothing for me. But I digress. Here's a list, in no particular order, of my 10 favorite Christmas songs. Sleigh Ride - Arthur Fiedler and the Boston Pops This one's my all-time favorite. It's an instrumental version that's been around since long before I was born, that I first heard on an album my mother would play when I was a little kid. My earliest memory of it was from when I was about 4 or 5 years old. I think the track itself originates in ...

How to Cast an Injected Service as a Mock in Angular Unit Tests

I've been meaning to write this for a while. Normally in my Angular unit tests, I set up my service mocks and then let dependency injection treat them as if they're the real thing. But sometimes you'll need to cast a service mock as a spy so you can do things like reset the calls it's made. And it's one of those things I always have to think back and remember "How did I do that last time?". Here's an example of how: const mockScoreAdminService = TestBed.inject(ScoreAdminService) as jasmine.SpyObj<ScoreAdminService>; mockScoreAdminService.processScores.calls.reset(); This code casts the service mock, which is treated as the real service type, to a Jasmine spy object. It then resets the calls made to the processScores  method to zero. I hope this helps someone!

Setting Default Values in an Angular Reactive Form

Something I ran into a few months back was that Angular won't reset a FormControl back to its initial value if you call reset()  on the FormGroup unless that FormControl was created with nonNullable: true . Here's an example:   private createForms ( formBuilder : FormBuilder ) : void {     //For the initial values to be considered the *default* values, we need to specify nonNullable: true.     //There used to be a dedicated property for this, but they deprecated it.     this . searchForm = formBuilder . group < ISearchForm >({       adminYear : new FormControl < number >( null , { validators : Validators . required }),       admin : new FormControl < string >( 'All' , { nonNullable : true , validators : Validators . required }), //Validator is kind of pointless here, as there WILL always be a value       examName : new FormControl < string | null >( null ), ...