my-element_test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @license
  3. * Copyright 2021 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. import {MyElement} from '../my-element.js';
  7. import {fixture, html} from '@open-wc/testing';
  8. const assert = chai.assert;
  9. suite('my-element', () => {
  10. test('is defined', () => {
  11. const el = document.createElement('my-element');
  12. assert.instanceOf(el, MyElement);
  13. });
  14. test('renders with default values', async () => {
  15. const el = await fixture(html`<my-element></my-element>`);
  16. assert.shadowDom.equal(
  17. el,
  18. `
  19. <h1>Hello, World!</h1>
  20. <button part="button">Click Count: 0</button>
  21. <slot></slot>
  22. `
  23. );
  24. });
  25. test('renders with a set name', async () => {
  26. const el = await fixture(html`<my-element name="Test"></my-element>`);
  27. assert.shadowDom.equal(
  28. el,
  29. `
  30. <h1>Hello, Test!</h1>
  31. <button part="button">Click Count: 0</button>
  32. <slot></slot>
  33. `
  34. );
  35. });
  36. test('handles a click', async () => {
  37. const el = (await fixture(html`<my-element></my-element>`)) as MyElement;
  38. const button = el.shadowRoot!.querySelector('button')!;
  39. button.click();
  40. await el.updateComplete;
  41. assert.shadowDom.equal(
  42. el,
  43. `
  44. <h1>Hello, World!</h1>
  45. <button part="button">Click Count: 1</button>
  46. <slot></slot>
  47. `
  48. );
  49. });
  50. test('styling applied', async () => {
  51. const el = (await fixture(html`<my-element></my-element>`)) as MyElement;
  52. await el.updateComplete;
  53. assert.equal(getComputedStyle(el).paddingTop, '16px');
  54. });
  55. });