Skip to content

Commit

Permalink
test: improving types
Browse files Browse the repository at this point in the history
  • Loading branch information
willmendesneto committed Aug 17, 2020
1 parent 7b636fb commit ea61c70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
@@ -1,4 +1,4 @@
import { Component, NO_ERRORS_SCHEMA, PLATFORM_ID } from '@angular/core';
import { Component, PLATFORM_ID } from '@angular/core';
import { async as waitForAsync, TestBed } from '@angular/core/testing';
import { start, end } from 'perf-marks/marks';

Expand Down Expand Up @@ -58,7 +58,6 @@ describe('NgxSkeletonLoaderComponent', () => {
fixture = TestBed.configureTestingModule({
declarations: [ContainerComponent, NgxSkeletonLoaderComponent],
providers: [{ provide: PLATFORM_ID, useValue: 'browser' }],
schemas: [NO_ERRORS_SCHEMA],
}).createComponent(ContainerComponent);
fixture.detectChanges();
}),
Expand Down Expand Up @@ -141,18 +140,17 @@ describe('NgxSkeletonLoaderComponent', () => {
});

describe('When rendering server side', () => {
let spyStart;
let spyEnd;
let ngxSkeletonLoaderComponent;
let spyStart: jasmine.Spy;
let spyEnd: jasmine.Spy;
let ngxSkeletonLoaderComponent: NgxSkeletonLoaderComponent;

beforeEach(() => {
spyStart = jasmine.createSpy('start', start);
spyEnd = jasmine.createSpy('start', end);

ngxSkeletonLoaderComponent = TestBed.createComponent<NgxSkeletonLoaderComponent>(NgxSkeletonLoaderComponent)
.componentInstance;

spyOn<NgxSkeletonLoaderComponent, 'isBrowser'>(ngxSkeletonLoaderComponent, 'isBrowser').and.returnValue(false);
ngxSkeletonLoaderComponent.isBrowser = false;
});

it('should not call perf-marks render and load marks', () => {
Expand Down
Expand Up @@ -20,11 +20,14 @@ export class NgxSkeletonLoaderComponent implements OnInit, AfterViewInit, OnDest
@Input() theme: { [k: string]: string } = {};

items: Array<any> = [];
isBrowser: boolean;

constructor(@Inject(PLATFORM_ID) private readonly platformId: any) {}
constructor(@Inject(PLATFORM_ID) private readonly platformId: any) {
this.isBrowser = isPlatformBrowser(this.platformId);
}

ngOnInit() {
if (this.isBrowser()) {
if (this.isBrowser) {
start('NgxSkeletonLoader:Rendered');
start('NgxSkeletonLoader:Loaded');
}
Expand All @@ -45,18 +48,14 @@ export class NgxSkeletonLoaderComponent implements OnInit, AfterViewInit, OnDest
}

ngAfterViewInit() {
if (this.isBrowser()) {
if (this.isBrowser) {
end('NgxSkeletonLoader:Rendered');
}
}

ngOnDestroy() {
if (this.isBrowser()) {
if (this.isBrowser) {
end('NgxSkeletonLoader:Loaded');
}
}

isBrowser(): boolean {
return isPlatformBrowser(this.platformId);
}
}
2 changes: 0 additions & 2 deletions src/app/app.component.spec.ts
@@ -1,12 +1,10 @@
import { TestBed, async } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
}));

Expand Down

0 comments on commit ea61c70

Please sign in to comment.