Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed May 15, 2024
1 parent bd778b0 commit 8e38478
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/runtime/initialize-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export const initializeComponent = async (
* ```html
* <script type="module">
* import { MyComponent } from 'my-stencil-component-library';
* console.log(1, MyComponent, customElements);
* customElements.define('my-other-component', MyComponent);
* </script>
* ```
Expand Down
3 changes: 2 additions & 1 deletion test/wdio/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const testRequiresManualSetup =
window.__wdioSpec__.includes('custom-elements-output-tag-class-different') ||
window.__wdioSpec__.includes('custom-elements-delegates-focus') ||
window.__wdioSpec__.includes('custom-elements-output') ||
window.__wdioSpec__.includes('global-script');
window.__wdioSpec__.includes('global-script') ||
window.__wdioSpec__.endsWith('custom-tag-name.test.tsx');

/**
* setup all components defined in tests except for those where we want ot manually setup
Expand Down
25 changes: 25 additions & 0 deletions test/wdio/watch-native-attributes/custom-tag-name.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { h } from '@stencil/core';
import { render } from '@wdio/browser-runner/stencil';

import { WatchNativeAttributes } from '../test-components/watch-native-attributes.js';

describe('watch native attributes', () => {
beforeEach(() => {
customElements.define('some-custom-element', WatchNativeAttributes);
render({
template: () => <some-custom-element aria-label="myStartingLabel"></some-custom-element>,
});
});

it('triggers the callback for the watched attribute', async () => {
const $cmp = $('some-custom-element');
await $cmp.waitForExist();

await expect($cmp).toHaveText('Label: myStartingLabel\nCallback triggered: false');

const cmp = document.querySelector('some-custom-element');
cmp.setAttribute('aria-label', 'myNewLabel');

await expect($cmp).toHaveText('Label: myNewLabel\nCallback triggered: true');
});
});

0 comments on commit 8e38478

Please sign in to comment.