Created
November 10, 2019 09:09
-
-
Save mraible/6799ef0f466ff062f47c5c86b942a80b to your computer and use it in GitHub Desktop.
Unit Test in Angular 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | |
import { SearchComponent } from './search.component'; | |
import { MockSearchService } from '../shared/search/mocks/search.service.mock'; | |
import { MockActivatedRoute } from '../shared/search/mocks/routes'; | |
import { SearchService } from '../shared'; | |
import { ActivatedRoute } from '@angular/router'; | |
import { FormsModule } from '@angular/forms'; | |
import { RouterTestingModule } from '@angular/router/testing'; | |
describe('SearchComponent', () => { | |
let component: SearchComponent; | |
let fixture: ComponentFixture<SearchComponent>; | |
let mockActivatedRoute: MockActivatedRoute; | |
beforeEach(async(() => { | |
mockActivatedRoute = new MockActivatedRoute({term: 'peyton'}); | |
TestBed.configureTestingModule({ | |
declarations: [SearchComponent], | |
providers: [ | |
{provide: SearchService, useClass: MockSearchService}, | |
{provide: ActivatedRoute, useValue: mockActivatedRoute} | |
], | |
imports: [FormsModule, RouterTestingModule] | |
}).compileComponents(); | |
})); | |
beforeEach(() => { | |
fixture = TestBed.createComponent(SearchComponent); | |
component = fixture.componentInstance; | |
fixture.detectChanges(); | |
}); | |
it('should create', () => { | |
expect(component).toBeTruthy(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result is: