-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(testing): prevent
find
from throwing error when query has no match
This commit fixes an issue w/ our Puppeteer testing implementation where the `find()` method would throw an error if the query had no matching elements. Fixes: #5639 STENCIL-1256
- Loading branch information
1 parent
76c5d54
commit c4522d9
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Component, h, Host } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'empty-cmp', | ||
shadow: true, | ||
}) | ||
export class EmptyComponent { | ||
render() { | ||
return <Host>I have no children!</Host>; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
test/end-to-end/src/non-existent-element/non-existent-element.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
|
||
describe('Querying non-existent element(s)', () => { | ||
it('returns `null` if the element does not exist', async () => { | ||
// create a new puppeteer page | ||
const page = await newE2EPage({ | ||
html: ` | ||
<empty-cmp></empty-cmp> | ||
`, | ||
}); | ||
|
||
const elm = await page.find('empty-cmp >>> .non-existent'); | ||
expect(elm).toBeNull(); | ||
}); | ||
|
||
it('returns an empty array if no elements match the selector', async () => { | ||
// create a new puppeteer page | ||
const page = await newE2EPage({ | ||
html: ` | ||
<empty-cmp></empty-cmp> | ||
`, | ||
}); | ||
|
||
const elm = await page.findAll('empty-cmp >>> .non-existent'); | ||
expect(elm).toBe([]); | ||
}); | ||
}); |