diff --git a/README.md b/README.md index c8888c9b..bd5c435c 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,7 @@ To install spectator via Yarn run: selector: 'app-button', template: ` - `, - styles: [] + ` }) export class ButtonComponent { @Input() className = 'success'; @@ -72,7 +71,12 @@ describe('ButtonComponent', () => { let spectator: Spectator; 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'); @@ -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' }); }); }); @@ -109,7 +115,7 @@ describe('ButtonComponent', () => { @Component({ selector: 'zippy', template: ` -
+
{{ visible ? 'Close' : 'Open' }} {{title}}
@@ -297,6 +303,10 @@ describe('TodosService', () => { it('should', () => { let otherService = spectator.get(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(); }); diff --git a/src/app/todos.service.spec.ts b/src/app/todos.service.spec.ts index 2b1b0698..c5716b12 100644 --- a/src/app/todos.service.spec.ts +++ b/src/app/todos.service.spec.ts @@ -1,6 +1,5 @@ import { TodosService } from "./todos.service"; import { createService } from "../lib/src/service"; -import { of } from "rxjs/observable/of"; class OtherService { add() {} @@ -15,7 +14,10 @@ describe("TodosService", () => { it("should", () => { // let otherService = spectator.get(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(); }); }); diff --git a/src/lib/src/config.ts b/src/lib/src/config.ts index 8396b3d6..34b3b3fb 100644 --- a/src/lib/src/config.ts +++ b/src/lib/src/config.ts @@ -19,7 +19,7 @@ export type SpectatorOptions = TestModuleMetadata & component?: Type; shallow?: boolean; disableAnimations?: boolean; - host: Type; + host?: Type; }; const defaultOptions: SpectatorOptions = {