Skip to content

Commit 8a8637c

Browse files
cuberootalexmirea
authored andcommitted
Fix error when using byContentVal decorator (#3)
* Fix error when using byContentVal decorator I was getting an error about writing to a read-only property when I used `@byContentVal` * Add a test that modifies a child’s content Add a test that modifies the content of a child that is watched using `@byContentVal` to make sure that the model updates
1 parent 966611c commit 8a8637c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/dom-model/DOMDecorators.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function makeDecorator(callback) {
2828
let byContentVal = makeDecorator(function() {
2929
return function (target, key, descriptor) {
3030
if (target.addProperty) {
31+
descriptor.writable = true;
3132
target.addProperty(key, (element) => {
3233
return element && element.innerText;
3334
});

test/dom-model/DOMModelTest.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@ describe("DOMModel", () => {
183183
option.setAttribute("value", "optionNew");
184184
});
185185

186+
it("updates the value when content changes", (done) => {
187+
let option = element.querySelector(`option[value="option2"]`);
188+
expect(option).to.exist;
189+
element.addEventListener("_updateModel", (event) => {
190+
let newValue = event.detail[0].value;
191+
expect(newValue).to.exist;
192+
expect(newValue).to.be.an('array');
193+
expect(newValue).to.have.lengthOf(4);
194+
expect(newValue[1].text).to.equal("Changed Option Label");
195+
done();
196+
});
197+
option.innerText = 'Changed Option Label';
198+
});
199+
186200
it("updates when removing item", (done) => {
187201
let option = element.querySelector(`option[value="option2"]`);
188202
expect(option).to.exist;

0 commit comments

Comments
 (0)