-
Notifications
You must be signed in to change notification settings - Fork 787
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(runtime): allow watchers to fire w/ no Stencil members (#5855)
* fix(runtime): allow watchers to fire w/ no Stencil members Fixes #5854 STENCIL-1338 * resolve test failures
- Loading branch information
1 parent
6ac07ec
commit 850ad4f
Showing
4 changed files
with
51 additions
and
4 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,24 @@ | ||
import { h } from '@stencil/core'; | ||
import { render } from '@wdio/browser-runner/stencil'; | ||
|
||
describe('watch native attributes w/ no Stencil members', () => { | ||
beforeEach(() => { | ||
render({ | ||
template: () => ( | ||
<watch-native-attributes-no-members aria-label="myStartingLabel"></watch-native-attributes-no-members> | ||
), | ||
}); | ||
}); | ||
|
||
it('triggers the callback for the watched attribute', async () => { | ||
const $cmp = $('watch-native-attributes-no-members'); | ||
await $cmp.waitForExist(); | ||
|
||
await expect($cmp).toHaveText('Label: myStartingLabel\nCallback triggered: false'); | ||
|
||
const cmp = document.querySelector('watch-native-attributes-no-members'); | ||
cmp.setAttribute('aria-label', 'myNewLabel'); | ||
|
||
await expect($cmp).toHaveText('Label: myNewLabel\nCallback triggered: true'); | ||
}); | ||
}); |
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,23 @@ | ||
import { Component, Element, forceUpdate, h, Watch } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'watch-native-attributes-no-members', | ||
}) | ||
export class WatchNativeAttributesNoMembers { | ||
@Element() el!: HTMLElement; | ||
|
||
private callbackTriggered = false; | ||
|
||
@Watch('aria-label') | ||
onAriaLabelChange() { | ||
this.callbackTriggered = true; | ||
forceUpdate(this); | ||
} | ||
|
||
render() { | ||
return [ | ||
<p>Label: {this.el.getAttribute('aria-label')}</p>, | ||
<p>Callback triggered: {`${this.callbackTriggered}`}</p>, | ||
]; | ||
} | ||
} |