Skip to content

Commit

Permalink
test: Just check that addEventListener is called
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Aug 15, 2023
1 parent f1c954e commit 99cf253
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions test/browser/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,35 +95,6 @@ describe('event handling', () => {
expect(click).to.have.been.calledOnce.and.calledWith(1);
});

// Uniquely named in that the base event names end with 'Capture'
it('should support got/lost pointer capture', () => {
let ongotpointercapture = sinon.spy(),
onlostpointercapture = sinon.spy();

let firePointerEvent = (on, type) =>
on.dispatchEvent(new PointerEvent(type, { pointerId: 1 }));

render(
<div
onPointerDown={e => e.target.setPointerCapture(e.pointerId)}
onGotPointerCapture={ongotpointercapture}
onLostPointerCapture={onlostpointercapture}
/>,
scratch
);

firePointerEvent(scratch.childNodes[0], 'pointerdown');
expect(ongotpointercapture).to.have.been.calledOnce;
expect(onlostpointercapture).to.not.have.been.called;

ongotpointercapture.resetHistory();
onlostpointercapture.resetHistory();

firePointerEvent(scratch.childNodes[0], 'pointerup');
expect(ongotpointercapture).to.not.have.been.called;
expect(onlostpointercapture).to.have.been.calledOnce;
});

it('should update event handlers', () => {
let click1 = sinon.spy();
let click2 = sinon.spy();
Expand Down Expand Up @@ -228,4 +199,38 @@ describe('event handling', () => {
expect(click, 'click').to.have.been.calledOnce;
});
}

// Uniquely named in that the base event names end with 'Capture'
it('should support (got|lost)PointerCapture events', () => {
let gotPointerCapture = sinon.spy(),
gotPointerCaptureCapture = sinon.spy(),
lostPointerCapture = sinon.spy(),
lostPointerCaptureCapture = sinon.spy();

render(
<div
onGotPointerCapture={gotPointerCapture}
onLostPointerCapture={lostPointerCapture}
/>,
scratch
);

expect(proto.addEventListener)
.to.have.been.calledTwice.and.to.have.been.calledWith('gotpointercapture')
.and.calledWith('lostpointercapture');

proto.addEventListener.resetHistory();

render(
<div
onGotPointerCaptureCapture={gotPointerCaptureCapture}
onLostPointerCaptureCapture={lostPointerCaptureCapture}
/>,
scratch
);

expect(proto.addEventListener)
.to.have.been.calledTwice.and.to.have.been.calledWith('gotpointercapture')
.and.calledWith('lostpointercapture');
});
});

0 comments on commit 99cf253

Please sign in to comment.