[go: nahoru, domu]

Skip to content

Commit

Permalink
Replace bad sinon stub in mouse tests
Browse files Browse the repository at this point in the history
It screwed up important calls inside the code being tested. Avoid
the stub by creating a temporary element with the desired properties.
  • Loading branch information
CendioOssman committed Aug 16, 2018
1 parent ab1ace3 commit 7407c1f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tests/test.mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ import Mouse from '../core/input/mouse.js';
describe('Mouse Event Handling', function() {
"use strict";

// This function is only used on target (the canvas)
// and for these tests we can assume that the canvas is 100x100
// located at coordinates 10x10
sinon.stub(Element.prototype, 'getBoundingClientRect').returns(
{left: 10, right: 110, top: 10, bottom: 110, width: 100, height: 100});
const target = document.createElement('canvas');
let target;

beforeEach(function () {
// For these tests we can assume that the canvas is 100x100
// located at coordinates 10x10
target = document.createElement('canvas');
target.style.position = "absolute";
target.style.top = "10px";
target.style.left = "10px";
target.style.width = "100px";
target.style.height = "100px";
document.body.appendChild(target);
});
afterEach(function () {
document.body.removeChild(target);
target = null;
});

// The real constructors might not work everywhere we
// want to run these tests
Expand Down

0 comments on commit 7407c1f

Please sign in to comment.