Skip to content

Commit

Permalink
fix(jest): fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkluijk committed Nov 20, 2018
1 parent 2b7d2a5 commit 7f058b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions projects/spectator/src/lib/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as customMatchers from './matchers';
import { By } from '@angular/platform-browser';
import { HostComponent, initialModule, SpectatorOptions } from './config';
import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
import { isType } from './is-type';

export class SpectatorWithHost<C, H = HostComponent> extends Spectator<C> {
hostComponent: H;
Expand Down Expand Up @@ -63,11 +64,10 @@ export class SpectatorWithHost<C, H = HostComponent> extends Spectator<C> {
}
}

export function createHostComponentFactory<C, H = HostComponent>(options: SpectatorOptions<C, H> | Type<C>): (template: string, detectChanges?: boolean, complexInputs?: Partial<C>) => SpectatorWithHost<C, H> {
const { component, moduleMetadata, host } = initialModule<C, H>(options, true);
export function createHostComponentFactory<C, H = HostComponent>(typeOrOptions: SpectatorOptions<C, H> | Type<C>): (template: string, detectChanges?: boolean, complexInputs?: Partial<C>) => SpectatorWithHost<C, H> {
const { component, moduleMetadata, host } = initialModule<C, H>(typeOrOptions, true);

const dc = (options as SpectatorOptions<C, H>).detectChanges;
(options as SpectatorOptions<C, H>).detectChanges = dc === undefined ? true : dc;
const dc = isType(typeOrOptions) || typeOrOptions.detectChanges === undefined ? true : typeOrOptions.detectChanges;

beforeEach(() => {
jasmine.addMatchers(customMatchers as any);
Expand Down Expand Up @@ -111,7 +111,7 @@ export function createHostComponentFactory<C, H = HostComponent>(options: Specta
});
}

if ((options as SpectatorOptions<C, H>).detectChanges && detectChanges) {
if (dc && detectChanges) {
spectatorWithHost.hostFixture.detectChanges();
}

Expand Down
6 changes: 3 additions & 3 deletions projects/spectator/src/lib/spectator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { async, TestBed } from '@angular/core/testing';
import * as customMatchers from './matchers';
import { Spectator } from './internals';
import { initialModule, SpectatorOptions } from './config';
import { isType } from './is-type';

/**
* Create factory-function for tested component
Expand All @@ -19,8 +20,7 @@ import { initialModule, SpectatorOptions } from './config';
export function createTestComponentFactory<T>(typeOrOptions: SpectatorOptions<T> | Type<T>): (componentParameters?: Partial<T>, detectChanges?: boolean) => Spectator<T> {
const { component, moduleMetadata } = initialModule<T>(typeOrOptions);

const dc = (options as SpectatorOptions<T>).detectChanges;
(options as SpectatorOptions<T>).detectChanges = dc === undefined ? true : dc;
const dc = isType(typeOrOptions) || typeOrOptions.detectChanges === undefined ? true : typeOrOptions.detectChanges;

beforeEach(() => {
jasmine.addMatchers(customMatchers as any);
Expand Down Expand Up @@ -55,7 +55,7 @@ export function createTestComponentFactory<T>(typeOrOptions: SpectatorOptions<T>
spectator.component[input] = inputs[input];
});

if ((options as SpectatorOptions<T>).detectChanges && detectChanges) {
if (dc && detectChanges) {
spectator.detectChanges();
}
return spectator;
Expand Down
2 changes: 1 addition & 1 deletion src/app/form-input/form-input.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { FormInputComponent } from './form-input.component';
import { createHostComponentFactory, SpectatorWithHost, Spectator, createTestComponentFactory } from 'projects/spectator/src/lib';
import { createHostComponentFactory, SpectatorWithHost, Spectator, createTestComponentFactory } from '@netbasal/spectator';

describe('FormInputComponent', () => {
let host: SpectatorWithHost<FormInputComponent>;
Expand Down

0 comments on commit 7f058b3

Please sign in to comment.