Skip to content

Commit

Permalink
fix(query): query now returns the right generic
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBasal committed Apr 13, 2018
1 parent a3eb917 commit 2e69a09
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/app/view-children/view-children.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
createHostComponentFactory,
SpectatorWithHost
} from "../../lib/src/host";
import { ElementRef } from "@angular/core";

describe("ViewChildrenComponent", () => {
let spectator: Spectator<ViewChildrenComponent>;
Expand All @@ -28,6 +29,10 @@ describe("ViewChildrenComponent", () => {
);
const div = spectator.query("div");
const component = spectator.query<ChildComponent>(ChildComponent);
const { nativeElement } = spectator.query<ElementRef>(ChildComponent, {
read: ElementRef
});

const button = spectator.query("button");

expect(serviceFromChild).toBeDefined();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"printWidth": 1000,
"printWidth": 10000,
"parser": "typescript"
}
14 changes: 7 additions & 7 deletions src/lib/src/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export class Spectator<C> {
* @param {{read}} options
* @returns {T}
*/
query<T>(directiveOrSelector: string, options?: { read }): Element;
query<T>(directiveOrSelector: Type<T>, options?: { read }): T;
query<T>(directiveOrSelector: Type<T> | string, options: { read } = { read: undefined }): T {
query<R>(directiveOrSelector: string, options?: { read }): Element;
query<R>(directiveOrSelector: Type<any>, options?: { read }): R;
query<R>(directiveOrSelector: Type<any> | string, options: { read } = { read: undefined }): R {
return _getChild(this.debugElement)(directiveOrSelector, options);
}

Expand All @@ -60,9 +60,9 @@ export class Spectator<C> {
* @param {{read}} options
* @returns {T[]}
*/
queryAll<T>(directiveOrSelector: string, options?: { read }): Element[];
queryAll<T>(directiveOrSelector: Type<T>, options?: { read }): T[];
queryAll<T>(directiveOrSelector: Type<T> | string, options: { read } = { read: undefined }): T[] {
queryAll<R>(directiveOrSelector: string, options?: { read }): Element[];
queryAll<R>(directiveOrSelector: Type<any>, options?: { read }): R[];
queryAll<R>(directiveOrSelector: Type<any> | string, options: { read } = { read: undefined }): R[] {
return _getChildren(this.debugElement)(directiveOrSelector, options);
}

Expand Down Expand Up @@ -253,7 +253,7 @@ export class Spectator<C> {
* @private
*/
export function _getChild(debugElementRoot: DebugElement) {
return function<T>(directiveOrSelector: Type<T> | string, options: { read } = { read: undefined }): T {
return function<T, R>(directiveOrSelector: Type<T> | string, options: { read } = { read: undefined }): R {
let debugElement: DebugElement;

if (typeof directiveOrSelector === 'string') {
Expand Down

0 comments on commit 2e69a09

Please sign in to comment.