Skip to content

Commit

Permalink
fix: Include undefined in the return type of get (#2392)
Browse files Browse the repository at this point in the history
  • Loading branch information
glen-84 authored Mar 7, 2022
1 parent 44de9c0 commit 00a0f6f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/api/attributes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,8 @@ describe('$(...)', () => {
it('(fn) : should work with no initial class attribute', () => {
const $inputs = cheerio.load(inputs);
$inputs('input, select').toggleClass(function () {
return $inputs(this).get(0).tagName === 'select'
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- `get` should never return undefined here.
return $inputs(this).get(0)!.tagName === 'select'
? 'selectable'
: 'inputable';
});
Expand Down
8 changes: 4 additions & 4 deletions src/api/manipulation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,16 +738,16 @@ describe('$(...)', () => {
const $style = $('<style>.foo {}</style>');
$fruits.prepend($style);
const styleTag = $fruits.children().get(0);
expect(styleTag.tagName).toBe('style');
expect(styleTag.children[0]).toHaveProperty('data', '.foo {}');
expect(styleTag?.tagName).toBe('style');
expect(styleTag?.children[0]).toHaveProperty('data', '.foo {}');
});

it('($(...)) : should add script element as first child', () => {
const $script = $('<script>var foo;</script>');
$fruits.prepend($script);
const scriptTag = $fruits.children().get(0);
expect(scriptTag.tagName).toBe('script');
expect(scriptTag.children[0]).toHaveProperty('data', 'var foo;');
expect(scriptTag?.tagName).toBe('script');
expect(scriptTag?.children[0]).toHaveProperty('data', 'var foo;');
});

it('(Node) : should add node as first child', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/traversing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ export function eq<T>(this: Cheerio<T>, i: number): Cheerio<T> {
* @returns The element at the `i`th position.
* @see {@link https://api.jquery.com/get/}
*/
export function get<T>(this: Cheerio<T>, i: number): T;
export function get<T>(this: Cheerio<T>, i: number): T | undefined;
/**
* Retrieve all elements matched by the Cheerio object, as an array.
*
Expand Down

0 comments on commit 00a0f6f

Please sign in to comment.