|
1 | 1 | import {controller} from '../lib/controller.js' |
| 2 | +import {attr} from '../lib/attr.js' |
2 | 3 |
|
3 | 4 | describe('controller', () => { |
4 | 5 | let root |
@@ -102,4 +103,35 @@ describe('controller', () => { |
102 | 103 | // eslint-disable-next-line github/unescaped-html-literal |
103 | 104 | root.innerHTML = '<parent-element><child-element></child-element></parent-element>' |
104 | 105 | }) |
| 106 | + |
| 107 | + describe('attrs', () => { |
| 108 | + let attrValues = [] |
| 109 | + class AttributeTestElement extends HTMLElement { |
| 110 | + foo = 'baz' |
| 111 | + attributeChangedCallback() { |
| 112 | + attrValues.push(this.getAttribute('data-foo')) |
| 113 | + attrValues.push(this.foo) |
| 114 | + } |
| 115 | + } |
| 116 | + controller(AttributeTestElement) |
| 117 | + attr(AttributeTestElement.prototype, 'foo') |
| 118 | + |
| 119 | + beforeEach(() => { |
| 120 | + attrValues = [] |
| 121 | + }) |
| 122 | + |
| 123 | + it('initializes attrs as attributes in attributeChangedCallback', () => { |
| 124 | + const el = document.createElement('attribute-test') |
| 125 | + el.foo = 'bar' |
| 126 | + el.attributeChangedCallback() |
| 127 | + expect(attrValues).to.eql(['bar', 'bar']) |
| 128 | + }) |
| 129 | + |
| 130 | + it('initializes attributes as attrs in attributeChangedCallback', () => { |
| 131 | + const el = document.createElement('attribute-test') |
| 132 | + el.setAttribute('data-foo', 'bar') |
| 133 | + el.attributeChangedCallback() |
| 134 | + expect(attrValues).to.eql(['bar', 'bar']) |
| 135 | + }) |
| 136 | + }) |
105 | 137 | }) |
0 commit comments