From the course: Angular: Testing and Debugging

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Solution: Custom test bed wrapper

Solution: Custom test bed wrapper - Angular Tutorial

From the course: Angular: Testing and Debugging

Start my 1-month free trial

Solution: Custom test bed wrapper

(upbeat music) - Okay. Here's my solution for the challenge. Keep in mind that my solution and your solution may be different, and that's okay. I made a class called CustomTestBed using the same ng generate commands we've used in previous videos. This class implements Angular's TestBed has a partial. Partial is a utility type introduced in recent versions of TypeScript. It returns a version of whatever type you pass in with all its properties set as optional. It's a great tool for things like this, because we get all the benefits of type safety without needing to implement all of TestBed's properties. Next, I made my own version of configureTestingModule. It has an object full of default values for the testing module config. This is where we store things like the WebStorageService which we want to inject into all our tests. I then return a copy of Angular's TestBed, calling configureTestingModule, and passing in a modified configure object. I use object data sign to merge the default…

Contents