File tree Expand file tree Collapse file tree
addon-test-support/@ember/test-helpers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import getRootElement from './get-root-element' ;
22import Target , { isDocument , isElement } from './-target' ;
33
4+ function getElement <
5+ K extends keyof ( HTMLElementTagNameMap | SVGElementTagNameMap )
6+ > ( target : K ) : ( HTMLElementTagNameMap | SVGElementTagNameMap ) [ K ] | null ;
7+ function getElement < K extends keyof HTMLElementTagNameMap > (
8+ target : K
9+ ) : HTMLElementTagNameMap [ K ] | null ;
10+ function getElement < K extends keyof SVGElementTagNameMap > (
11+ target : K
12+ ) : SVGElementTagNameMap [ K ] | null ;
413function getElement ( target : string ) : Element | null ;
514function getElement ( target : Element ) : Element ;
615function getElement ( target : Document ) : Document ;
Original file line number Diff line number Diff line change 11import getElements from './-get-elements' ;
22import { toArray } from '../ie-11-polyfills' ;
33
4+ // Derived, with modification, from the types for `querySelectorAll`. These
5+ // would simply be defined as a tweaked re-export as `querySelector` is, but it
6+ // is non-trivial (to say the least!) to preserve overloads like this while also
7+ // changing the return type (from `NodeListOf` to `Array`).
48/**
59 Find all elements matched by the given selector. Similar to calling
610 `querySelectorAll()` on the test root element, but returns an array instead
@@ -16,6 +20,16 @@ import { toArray } from '../ie-11-polyfills';
1620 </caption>
1721 find('#foo');
1822*/
23+ export default function findAll <
24+ K extends keyof ( HTMLElementTagNameMap | SVGElementTagNameMap )
25+ > ( selector : K ) : Array < ( HTMLElementTagNameMap | SVGElementTagNameMap ) [ K ] > ;
26+ export default function findAll < K extends keyof HTMLElementTagNameMap > (
27+ selector : K
28+ ) : Array < HTMLElementTagNameMap [ K ] > ;
29+ export default function findAll < K extends keyof SVGElementTagNameMap > (
30+ selector : K
31+ ) : Array < SVGElementTagNameMap [ K ] > ;
32+ export default function findAll ( selector : string ) : Element [ ] ;
1933export default function findAll ( selector : string ) : Element [ ] {
2034 if ( ! selector ) {
2135 throw new Error ( 'Must pass a selector to `findAll`.' ) ;
Original file line number Diff line number Diff line change 11import getElement from './-get-element' ;
22
3+ // Derived from `querySelector` types.
34/**
45 Find the first element matched by the given selector. Equivalent to calling
56 `querySelector()` on the test root element.
@@ -15,6 +16,16 @@ import getElement from './-get-element';
1516 findAll('.my-selector');
1617
1718*/
19+ export default function find <
20+ K extends keyof ( HTMLElementTagNameMap | SVGElementTagNameMap )
21+ > ( selector : K ) : ( HTMLElementTagNameMap | SVGElementTagNameMap ) [ K ] | null ;
22+ export default function find < K extends keyof HTMLElementTagNameMap > (
23+ selector : K
24+ ) : HTMLElementTagNameMap [ K ] | null ;
25+ export default function find < K extends keyof SVGElementTagNameMap > (
26+ selector : K
27+ ) : SVGElementTagNameMap [ K ] | null ;
28+ export default function find ( selector : string ) : Element | null ;
1829export default function find ( selector : string ) : Element | null {
1930 if ( ! selector ) {
2031 throw new Error ( 'Must pass a selector to `find`.' ) ;
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ export {
2929 default as setupRenderingContext ,
3030 render ,
3131 clearRender ,
32+ RenderingTestContext ,
3233} from './setup-rendering-context' ;
3334export type { RenderingTestContext } from './setup-rendering-context' ;
3435export { default as rerender } from './rerender' ;
Original file line number Diff line number Diff line change @@ -136,7 +136,15 @@ expectTypeOf(typeIn).toEqualTypeOf<
136136
137137// DOM Query Helpers
138138expectTypeOf ( find ) . toEqualTypeOf < ( selector : string ) => Element | null > ( ) ;
139+ expectTypeOf ( find ( 'a' ) ) . toEqualTypeOf < HTMLAnchorElement | SVGAElement | null > ( ) ;
140+ expectTypeOf ( find ( 'div' ) ) . toEqualTypeOf < HTMLDivElement | null > ( ) ;
141+ expectTypeOf ( find ( 'circle' ) ) . toEqualTypeOf < SVGCircleElement | null > ( ) ;
142+ expectTypeOf ( find ( '.corkscrew' ) ) . toEqualTypeOf < Element | null > ( ) ;
139143expectTypeOf ( findAll ) . toEqualTypeOf < ( selector : string ) => Array < Element > > ( ) ;
144+ expectTypeOf ( findAll ( 'a' ) ) . toEqualTypeOf < ( HTMLAnchorElement | SVGAElement ) [ ] > ( ) ;
145+ expectTypeOf ( findAll ( 'div' ) ) . toEqualTypeOf < HTMLDivElement [ ] > ( ) ;
146+ expectTypeOf ( findAll ( 'circle' ) ) . toEqualTypeOf < SVGCircleElement [ ] > ( ) ;
147+ expectTypeOf ( findAll ( '.corkscrew' ) ) . toEqualTypeOf < Element [ ] > ( ) ;
140148expectTypeOf ( getRootElement ) . toEqualTypeOf < ( ) => Element | Document > ( ) ;
141149
142150// Routing Helpers
You can’t perform that action at this time.
0 commit comments