Skip to content

Commit

Permalink
fix(host): mark host as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBasal committed Apr 1, 2018
1 parent f1a8dba commit 834b12f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ To install spectator via Yarn run:
selector: 'app-button',
template: `
<button class="{{className}}" (click)="onClick($event)">{{title}}</button>
`,
styles: []
`
})
export class ButtonComponent {
@Input() className = 'success';
Expand All @@ -72,7 +71,12 @@ describe('ButtonComponent', () => {
let spectator: Spectator<ButtonComponent>;
const createComponent = createTestComponentFactory(ButtonComponent);
// const createComponent = createTestComponentFactory({
// component: ButtonComponent,
// imports: [OtherModule]
// });
it('should set the "success" class by default', () => {
spectator = createComponent();
expect(spectator.query('button')).toHaveClass('success');
Expand All @@ -92,11 +96,13 @@ describe('ButtonComponent', () => {
});
it('should emit the $event on click', () => {
spectator = createComponent();
const detectChanges = false;
spectator = createComponent({}, detectChanges);
let output;
spectator.output<{ type: string }>('click').subscribe(result => output = result);
spectator.component.onClick({ type: 'click' });
spectator.detectChanges();
expect(output).toEqual({ type: 'click' });
});
});
Expand All @@ -109,7 +115,7 @@ describe('ButtonComponent', () => {
@Component({
selector: 'zippy',
template: `
<div class="zippy" id="zippy">
<div class="zippy">
<div (click)="toggle()" class="zippy__title">
<span class="arrow">{{ visible ? 'Close' : 'Open' }}</span> {{title}}
</div>
Expand Down Expand Up @@ -297,6 +303,10 @@ describe('TodosService', () => {
it('should', () => {
let otherService = spectator.get<OtherService>(OtherService);
otherService.someMethod.andReturn(customValue);
otherService.someMethod.and.callThrough();
otherService.someMethod.and.callFake(() => fake);
otherService.someMethod.and.throwError('Error');
otherService.someMethod.andCallFake(() => fake);
spectator.service.remove();
expect(spectator.service.someProp).toBeTruthy();
});
Expand Down
6 changes: 4 additions & 2 deletions src/app/todos.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TodosService } from "./todos.service";
import { createService } from "../lib/src/service";
import { of } from "rxjs/observable/of";

class OtherService {
add() {}
Expand All @@ -15,7 +14,10 @@ describe("TodosService", () => {

it("should", () => {
// let otherService = spectator.get<OtherService>(OtherService);
// otherService.add.andReturn(of(true));
// otherService.add.and.callThrough();
// otherService.add.and.callFake(() => fake);
// otherService.add.and.throwError('Error');
// otherService.add.andCallFake(() => fake);
spectator.service.remove();
});
});
2 changes: 1 addition & 1 deletion src/lib/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type SpectatorOptions<T = any, H = HostComponent> = TestModuleMetadata &
component?: Type<T>;
shallow?: boolean;
disableAnimations?: boolean;
host: Type<H>;
host?: Type<H>;
};

const defaultOptions: SpectatorOptions<any, any> = {
Expand Down

0 comments on commit 834b12f

Please sign in to comment.