Testing Notifications with Jasmine


Topic: Testing Notifications with Jasmine

waffaru asked 6 years ago

Hey,

After importing and using ToastModule for Notifications, my tests no longer pass. This was expected behaviour. However, the error I'm getting is as follows:

Error: StaticInjectorError(DynamicTestModule)[ToastrService -> InjectionToken ToastConfig]: 
  StaticInjectorError(Platform: core)[ToastrService -> InjectionToken ToastConfig]: 
    NullInjectorError: No provider for InjectionToken ToastConfig!

I have no idea what I should try importing to solve the issue. Importing ToastModule.forRoot() doesn't seem to fix the issue and neither does importing separate services.

Can you please point me to the right direction on how to make it so my component test actually creates? Thanks.


waffaru answered 6 years ago

Hello,

This was a mistake on my part. I was using NGX's ToastrModule before moving to this one and had a service still importing it that was being used by this component. Removing the dependency fixed my issue.


Arkadiusz Idzikowski staff answered 6 years ago

Hello,

Could you show the content of your module file and provide the html and ts code of the component in which you use toasts?


waffaru commented 6 years ago

Hello, please look at the answer below. I replied there to be able to codeblock the related code.


waffaru answered 6 years ago

Hey! The TS and HTML file in which I use toasts are completely fine and working. It's the tests I'm having issues with and setting up the Testbed for it.

Here's what the testbed looks like in my test file:

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        ReactiveFormsModule, FormsModule, InputsModule, WavesModule, TranslateModule,
        ToastModule.forRoot(), MDBBootstrapModulesPro, HttpClientModule, RouterTestingModule
      ],
      declarations: [
        (Bunch of unrelated declarations)
      ],
      providers: [{provide: FormBuilder, useValue: formBuilder}, PrincipalService, ToastService]
    })
    .compileComponents();
  }));

As for the .TS file that uses it, I just have a dependency-injected ToastService, and I use the service's error-method on a failed API call.

For the actual file I import ToastModule.forRoot() on a shared module and it works fine. But importing ToastModule.forRoot() on a testomodule doesn't seem to work.


Arkadiusz Idzikowski staff answered 6 years ago

Could you please send a simple demo to a.idzikowski@mdbootstrap.com so I can debug this problem on my end?


use ToastrModule.forRoot() instead of ToastModule.forRoot()


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 7.0.0
  • Device: PC
  • Browser: Firefox, Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No