-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
) Fixes: #3580 STENCIL-565
- Loading branch information
1 parent
970c5d2
commit 0e261d6
Showing
5 changed files
with
78 additions
and
1 deletion.
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
18 changes: 18 additions & 0 deletions
18
test/wdio/custom-elements-hierarchy-lifecycle/cmp-child.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,18 @@ | ||
import { Component, h } from '@stencil/core'; | ||
|
||
import { createAndAppendElement } from './cmp-util.js'; | ||
|
||
@Component({ | ||
tag: 'custom-elements-hierarchy-lifecycle-child', | ||
shadow: true, | ||
}) | ||
export class CustomElementsHierarchyLifecycleChild { | ||
async componentDidLoad(): Promise<void> { | ||
createAndAppendElement('DID LOAD CHILD'); | ||
return Promise.resolve(); | ||
} | ||
|
||
render() { | ||
return <p>CHILD CONTENT</p>; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/wdio/custom-elements-hierarchy-lifecycle/cmp-parent.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,18 @@ | ||
import { Component, h } from '@stencil/core'; | ||
|
||
import { createAndAppendElement } from './cmp-util.js'; | ||
|
||
@Component({ | ||
tag: 'custom-elements-hierarchy-lifecycle-parent', | ||
shadow: true, | ||
}) | ||
export class CustomElementsHierarchyLifecycleParent { | ||
async componentDidLoad(): Promise<void> { | ||
createAndAppendElement('DID LOAD PARENT'); | ||
return Promise.resolve(); | ||
} | ||
|
||
render() { | ||
return <custom-elements-hierarchy-lifecycle-child></custom-elements-hierarchy-lifecycle-child>; | ||
} | ||
} |
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,6 @@ | ||
export const createAndAppendElement = (text: string) => { | ||
const p = document.createElement('p'); | ||
p.textContent = text; | ||
|
||
document.body.appendChild(p); | ||
}; |
35 changes: 35 additions & 0 deletions
35
test/wdio/custom-elements-hierarchy-lifecycle/cmp.test.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,35 @@ | ||
import { Fragment, h } from '@stencil/core'; | ||
import { render } from '@wdio/browser-runner/stencil'; | ||
|
||
import { defineCustomElement as defineCustomElementChildCmp } from '../test-components/custom-elements-hierarchy-lifecycle-child.js'; | ||
import { defineCustomElement as defineCustomElementParentCmp } from '../test-components/custom-elements-hierarchy-lifecycle-parent.js'; | ||
|
||
describe('custom-elements-hierarchy-lifecycle', () => { | ||
before(() => { | ||
defineCustomElementChildCmp(); | ||
defineCustomElementParentCmp(); | ||
}); | ||
|
||
it('should call componentDidLoad in the child before the parent', async () => { | ||
expect(customElements.get('custom-elements-hierarchy-lifecycle-child')).toBeDefined(); | ||
expect(customElements.get('custom-elements-hierarchy-lifecycle-parent')).toBeDefined(); | ||
|
||
render({ | ||
template: () => ( | ||
<> | ||
<custom-elements-hierarchy-lifecycle-parent></custom-elements-hierarchy-lifecycle-parent> | ||
</> | ||
), | ||
}); | ||
|
||
const elm = document.querySelector('custom-elements-hierarchy-lifecycle-parent'); | ||
expect(elm.shadowRoot).toBeDefined(); | ||
|
||
await browser.waitUntil(() => Boolean(elm.shadowRoot.querySelector('custom-elements-hierarchy-lifecycle-child'))); | ||
|
||
expect(Array.from(document.querySelectorAll('p')).map((r) => r.textContent)).toEqual([ | ||
'DID LOAD CHILD', | ||
'DID LOAD PARENT', | ||
]); | ||
}); | ||
}); |