title: Unit test fails with NullInjectorError in Angular
body: <p>I'm new to Angular and I'm missing something when it comes to understanding how DI works. I'm currently trying to get a unit test to pass.</p>
  
  <p>Here is the code for the test;</p>
  
  <pre><code>import { TestBed } from '@angular/core/testing';
  import { HttpClientModule, HttpClient } from '@angular/common/http'
  import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
  import { InjectionToken } from '@angular/core';
  import { UserService } from './user.service';
  
  export const BASE_URL = new InjectionToken&lt;string&gt;('BASE_URL');
  
  describe('UserService', () =&gt; {
    beforeEach(() =&gt; TestBed.configureTestingModule({
      imports: [
        HttpClientTestingModule,
      ],
      providers: [
        { provide: BASE_URL, useValue: 'http://localhost' },
        UserService,
        HttpClient
      ]
    }));
  
    it('should be created', () =&gt; {
      const service: UserService = TestBed.get(UserService);
      expect(service).toBeTruthy();
    });
  });
  </code></pre>
  
  <p>Here is the code under test;</p>
  
  <pre><code>import { Injectable, Inject } from '@angular/core';
  import { HttpClient } from '@angular/common/http';
  
  import { User } from '@/_models';
  
  @Injectable({ providedIn: 'root' })
  export class UserService {
  
    private baseUrl: string
  
    constructor(private http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
      this.baseUrl = baseUrl
    }
  
    getAll() {
      return this.http.get&lt;User[]&gt;(`${this.baseUrl}/users`);
    }
  
    getById(id: number) {
      return this.http.get(`${this.baseUrl}/users/${id}`);
    }
  
    register(user: User) {
      return this.http.post(`${this.baseUrl}/users/register`, user);
    }
  
    update(user: User) {
      return this.http.put(`${this.baseUrl}/users/${user.id}`, user);
    }
  
    delete(id: number) {
      return this.http.delete(`${this.baseUrl}/users/${id}`);
    }
  }
  </code></pre>
  
  <p>This is my error;</p>
  
  <blockquote>
    <p>Error: StaticInjectorError(DynamicTestModule)[BASE_URL]:<br>
    StaticInjectorError(Platform: core)[BASE_URL]: 
        NullInjectorError: No provider for BASE_URL!</p>
  </blockquote>
  
  <p>Why am I getting this error and what do I need to do to rectify it?</p>