top-repo.component.spec.ts 2.12 KB
Newer Older
1
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
Meina Zhou's avatar
Meina Zhou committed
2
import { TranslateModule, TranslateService } from '@ngx-translate/core';
Meina Zhou's avatar
Meina Zhou committed
3
import { TopRepoComponent } from './top-repo.component';
Yogi_Wang's avatar
Yogi_Wang committed
4 5 6 7 8 9 10 11 12 13
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
import { ClarityModule } from '@clr/angular';
import { FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { of } from 'rxjs';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { MessageHandlerService } from '../../shared/message-handler/message-handler.service';
import { TopRepoService } from './top-repository.service';
describe('TopRepoComponent', () => {
Meina Zhou's avatar
Meina Zhou committed
14 15
    let component: TopRepoComponent;
    let fixture: ComponentFixture<TopRepoComponent>;
Yogi_Wang's avatar
Yogi_Wang committed
16 17 18 19 20 21 22 23
    const mockMessageHandlerService = {
        showSuccess: () => { },
        handleError: () => { },
        isAppLevel: () => { },
    };
    const mockTopRepoService = {
        getTopRepos: () => of([])
    };
24
    beforeEach(waitForAsync(() => {
Meina Zhou's avatar
Meina Zhou committed
25
        TestBed.configureTestingModule({
Yogi_Wang's avatar
Yogi_Wang committed
26 27 28
            schemas: [
                CUSTOM_ELEMENTS_SCHEMA
            ],
Meina Zhou's avatar
Meina Zhou committed
29
            imports: [
Yogi_Wang's avatar
Yogi_Wang committed
30 31 32 33 34 35 36
                BrowserAnimationsModule,
                ClarityModule,
                TranslateModule.forRoot(),
                FormsModule,
                RouterTestingModule,
                NoopAnimationsModule,
                HttpClientTestingModule
Meina Zhou's avatar
Meina Zhou committed
37 38 39
            ],
            declarations: [TopRepoComponent],
            providers: [
Yogi_Wang's avatar
Yogi_Wang committed
40 41 42 43
                TranslateService,
                { provide: TopRepoService, useValue: mockTopRepoService },
                { provide: MessageHandlerService, useValue: mockMessageHandlerService },

Meina Zhou's avatar
Meina Zhou committed
44
            ]
Meina Zhou's avatar
Meina Zhou committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58
        })
            .compileComponents();
    }));

    beforeEach(() => {
        fixture = TestBed.createComponent(TopRepoComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
    });

    it('should create', () => {
        expect(component).toBeTruthy();
    });
});