-
Notifications
You must be signed in to change notification settings - Fork 1
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
- Loading branch information
1 parent
2ae86ad
commit dba99f1
Showing
6 changed files
with
119 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
11 changes: 11 additions & 0 deletions
11
test/end-to-end/src/non-existent-element/empty-cmp-shadow.tsx
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 '@rindo/core'; | ||
|
||
@Component({ | ||
tag: 'empty-cmp-shadow', | ||
shadow: true, | ||
}) | ||
export class EmptyComponentShadow { | ||
render() { | ||
return <Host>I have no children!</Host>; | ||
} | ||
} |
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,12 @@ | ||
import { Component, h, Host } from '@rindo/core'; | ||
|
||
@Component({ | ||
tag: 'empty-cmp', | ||
shadow: false, | ||
scoped: false, | ||
}) | ||
export class EmptyComponent { | ||
render() { | ||
return <Host>I have no children!</Host>; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
import { newE2EPage } from '@rindo/core/testing'; | ||
|
||
describe('Querying non-existent element(s)', () => { | ||
describe('Shadow DOM', () => { | ||
it('returns `null` if the element does not exist', async () => { | ||
// create a new puppeteer page | ||
const page = await newE2EPage({ | ||
html: ` | ||
<empty-cmp-shadow></empty-cmp-shadow> | ||
`, | ||
}); | ||
|
||
const elm = await page.find('empty-cmp-shadow >>> .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-shadow></empty-cmp-shadow> | ||
`, | ||
}); | ||
|
||
const elm = await page.findAll('empty-cmp-shadow >>> .non-existent'); | ||
expect(elm).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('Light DOM', () => { | ||
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).toEqual([]); | ||
}); | ||
}); | ||
}); |
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,10 @@ | ||
# empty-cmp | ||
|
||
|
||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
---------------------------------------------- | ||
|
||
*Built with [RindoJS](https://rindojs.web.app/)* |