Angular 4 – Failed: Can’t resolve all parameters for ActivatedRoute: (?, ?, ?, ?, ?, ?, ?, ?)

You want to inject a fake ActivatedRoute to your component, since you create it yourself in the test, and the router thus doesn’t create it for you and inject an ActivatedRoute. So you can use something like this: describe(‘SomeComponent’, () => { const fakeActivatedRoute = { snapshot: { data: { … } } } as … Read more

Angular 6 – NullInjectorError: No provider for HttpClient in unit tests

import { TestBed } from ‘@angular/core/testing’; import { HttpClientTestingModule, HttpTestingController } from ‘@angular/common/http/testing’; import {HttpClientModule} from ‘@angular/common/http’; import { myService } from ‘./myservice’; describe(‘myService’, () => { beforeEach(() => TestBed.configureTestingModule({ imports: [HttpClientTestingModule], providers: [myService] })); it(‘should be created’, () => { const service: myService = TestBed.get(myService); expect(service).toBeTruthy(); }); it(‘should have getData function’, () => { … Read more

Expect not toThrow function with arguments – Jasmine

toThrow matcher requires function to be passed as argument to expect so you can simply wrap your function call in anonymous function: expect(function() { myFunc(arg1, arg2, arg3); }).not.toThrow(); You can also use bind to create new ‘version’ of your function that when called will be passed provided arguments: expect(myFunc.bind(null, arg1, arg2, arg3)).not.toThrow();

MatDialog Service Unit Test Angular 6 Error

Testing mat-dialogs can be tricky. I tend to use a spy object for the return from a dialog open (dialogRefSpyObj below) so I can more easily track and control tests. In your case it might look something like the following: describe(‘ModalService’, () => { let modalService: ModalService; let dialogSpy: jasmine.Spy; let dialogRefSpyObj = jasmine.createSpyObj({ afterClosed … Read more

How to get better test reports in the console?

Fixed by installing the karma-spec-reporter npm install karma-spec-reporter –save-dev and adding this my karma.config.js reporters: [‘spec’], According to karma documentation By default, Karma loads all NPM modules that are siblings to it and their name matches karma-*. but some users have had to add the following to their config plugins: [‘karma-spec-reporter’]

Unit test Angular with Jasmine and Karma, Error:Can’t bind to ‘xxx’ since it isn’t a known property of ‘xxxxxx’.

You need to add your second component when creating your testing module as that module is part of component 1. If you don’t the module won’t have my-component2 and the input will be invalid. TestBed.configureTestingModule({ declarations: [ MyComponent1Component, MyComponent2Component ], imports: [], providers: [MyService1Service, HttpClient, HttpHandler, HttpTestingController] })

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)