click(1) } onMouseDown={ mousedown } />, scratch);
expect(proto.addEventListener).to.have.been.calledTwice
.and.to.have.been.calledWith('click')
.and.calledWith('mousedown');
fireEvent(scratch.childNodes[0], 'click');
expect(click).to.have.been.calledOnce
.and.calledWith(1);
proto.addEventListener.reset();
click.reset();
render(
click(2) } />, scratch, scratch.firstChild);
expect(proto.addEventListener).not.to.have.been.called;
expect(proto.removeEventListener)
.to.have.been.calledOnce
.and.calledWith('mousedown');
fireEvent(scratch.childNodes[0], 'click');
expect(click).to.have.been.calledOnce
.and.to.have.been.calledWith(2);
fireEvent(scratch.childNodes[0], 'mousedown');
expect(mousedown).not.to.have.been.called;
proto.removeEventListener.reset();
click.reset();
mousedown.reset();
render(
, scratch, scratch.firstChild);
expect(proto.removeEventListener)
.to.have.been.calledOnce
.and.calledWith('click');
fireEvent(scratch.childNodes[0], 'click');
expect(click).not.to.have.been.called;
proto.addEventListener.restore();
proto.removeEventListener.restore();
});
it('should use capturing for events that do not bubble', () => {
let click = sinon.spy(),
focus = sinon.spy();
let root = render((
), scratch);
root.firstElementChild.click();
root.firstElementChild.focus();
expect(click, 'click').to.have.been.calledOnce;
if (DISABLE_FLAKEY!==true) {
// Focus delegation requires a 50b hack I'm not sure we want to incur
expect(focus, 'focus').to.have.been.calledOnce;
// IE doesn't set it
expect(click).to.have.been.calledWithMatch({ eventPhase: 0 }); // capturing
expect(focus).to.have.been.calledWithMatch({ eventPhase: 0 }); // capturing
}
});
it('should serialize style objects', () => {
let root = render((
test
), scratch);
let { style } = scratch.childNodes[0];
expect(style).to.have.property('color').that.equals('rgb(255, 255, 255)');
expect(style).to.have.property('background').that.contains('rgb(255, 100, 0)');
expect(style).to.have.property('backgroundPosition').that.equals('10px 10px');
expect(style).to.have.property('backgroundSize', 'cover');
expect(style).to.have.property('padding', '5px');
expect(style).to.have.property('top', '100px');
expect(style).to.have.property('left', '100%');
root = render((
test
), scratch, root);
expect(root).to.have.deep.property('style.cssText').that.equals('color: rgb(0, 255, 255);');
root = render((
test
), scratch, root);
expect(root).to.have.deep.property('style.cssText').that.equals('display: inline;');
root = render((
test
), scratch, root);
expect(root).to.have.deep.property('style.cssText').that.equals('background-color: rgb(0, 255, 255);');
});
it('should serialize class/className', () => {
render(
, scratch);
let { className } = scratch.childNodes[0];
expect(className).to.be.a.string;
expect(className.split(' '))
.to.include.members(['yes1', 'yes2', 'yes3', 'yes4', 'yes5'])
.and.not.include.members(['no1', 'no2', 'no3', 'no4', 'no5']);
});
it('should support dangerouslySetInnerHTML', () => {
let html = '
foo & bar ';
let root = render(
, scratch);
expect(scratch.firstChild).to.have.property('innerHTML', html);
expect(scratch.innerHTML).to.equal('
'+html+'
');
root = render(
ab
, scratch, root);
expect(scratch).to.have.property('innerHTML', `
ab
`);
root = render(
, scratch, root);
expect(scratch.innerHTML).to.equal('
'+html+'
');
});
it('should reconcile mutated DOM attributes', () => {
let check = p => render(
, scratch, scratch.lastChild),
value = () => scratch.lastChild.checked,
setValue = p => scratch.lastChild.checked = p;
check(true);
expect(value()).to.equal(true);
check(false);
expect(value()).to.equal(false);
check(true);
expect(value()).to.equal(true);
setValue(true);
check(false);
expect(value()).to.equal(false);
setValue(false);
check(true);
expect(value()).to.equal(true);
});
it('should ignore props.children if children are manually specified', () => {
expect(
c
).to.eql(
c
);
});
it('should reorder child pairs', () => {
let root = render((
), scratch, root);
let a = scratch.firstChild.firstChild;
let b = scratch.firstChild.lastChild;
expect(a).to.have.property('nodeName', 'A');
expect(b).to.have.property('nodeName', 'B');
root = render((
), scratch, root);
expect(scratch.firstChild.firstChild).to.have.property('nodeName', 'B');
expect(scratch.firstChild.lastChild).to.have.property('nodeName', 'A');
expect(scratch.firstChild.firstChild).to.equal(b);
expect(scratch.firstChild.lastChild).to.equal(a);
});
// Discussion: https://github.com/developit/preact/issues/287
('HTMLDataListElement' in window ? it : xit)('should allow
to pass through as an attribute', () => {
render((
0
50
100
), scratch);
let html = scratch.firstElementChild.firstElementChild.outerHTML;
expect(sortAttributes(html)).to.equal(sortAttributes('
'));
});
});