diff --git a/packages/projector/spec/projector.spec.js b/packages/projector/spec/projector.spec.js index d3cb453..0b1ccc6 100644 --- a/packages/projector/spec/projector.spec.js +++ b/packages/projector/spec/projector.spec.js @@ -51,11 +51,11 @@ describe('Projector', () => { } describe('getElement', () => { - it('getElement(null) method should to return the container.', () => { + it('should to return the container from a null id.', () => { expect(projector.getElement(null)).toBe(container); }); - it('getElement(id) method should to return the patched node.', () => { + it('should to return the patched node from an integer id.', () => { const id = add(h('div', { className: 'first' })); expect(projector.getElement(id)._id).toBe(id); }); @@ -245,10 +245,14 @@ describe('Projector', () => { it('do not propagate a removed sibling event', done => { let callCount = 1; function eventHandler(evt) { - expect(evt.target._id).toBe(Bid); - patch(Bid, { onclick: null }); - if (0 === callCount--) { - fail('Should not be called twice.'); + if (evt.target._id === Bid) { + patch(Bid, { onclick: null }); + if (0 === callCount--) { + fail('Should not be called twice.'); + } + } else { + expect(evt.target._id).toBe(Aid); + expect(callCount).toBe(0); } } projector.subscribe(eventHandler); @@ -261,7 +265,10 @@ describe('Projector', () => { return waitForNextFrame(); }) .then(() => { - // debugger; + projector.getElement(Aid).click(); + return waitForNextFrame(); + }) + .then(() => { projector.getElement(Bid).click(); return waitForNextFrame(); }) @@ -269,4 +276,49 @@ describe('Projector', () => { .catch(console.error.bind(console)); }); }); + + describe('setElementProperty', () => { + it('Can set element properties', () => { + const id = add(h('div', { className: 'first' })); + const el = projector.getElement(id); + expect(el.className).toBe('first'); + projector.setElementProperty(id, 'className', 'second'); + expect(el.className).toBe('second'); + }); + + it('Can set pathed element properties', () => { + const id = add(h('div', { className: 'first' })); + const el = projector.getElement(id); + expect(el.className).toBe('first'); + projector.setElementProperty(id, 'style.backgroundColor', 'blue'); + expect(el.style.backgroundColor).toBe('blue'); + }); + + it('Cannot set innerHTML', () => { + const id = add(h('div', { className: 'first' })); + const el = projector.getElement(id); + expect(el.className).toBe('first'); + try { + projector.setElementProperty(id, 'innerHTML', '