Skip to content

Instantly share code, notes, and snippets.

@danvk
Created March 6, 2015 18:31
Show Gist options
  • Save danvk/f531034587d7e3bbd1c7 to your computer and use it in GitHub Desktop.
Save danvk/f531034587d7e3bbd1c7 to your computer and use it in GitHub Desktop.
/**
* @fileoverview Tests for window.devicePixelRatio > 1.
*
* @author danvdk@gmail.com (Dan Vanderkam)
*/
describe("hidpi", function () {
var savePixelRatio;
beforeEach(function () {
savePixelRatio = window.devicePixelRatio;
window.devicePixelRatio = 2;
document.body.innerHTML = "<div id='graph'></div>";
});
afterEach(function () {
window.devicePixelRatio = savePixelRatio;
});
it("testDoesntCreateScrollbars", function () {
var sw = document.body.scrollWidth;
var cw = document.body.clientWidth;
var graph = document.getElementById("graph");
graph.style.width = "70%"; // more than half.
graph.style.height = "200px";
var opts = {};
var data = "X,Y\n" +
"0,-1\n" +
"1,0\n" +
"2,1\n" +
"3,0\n"
;
var g = new Dygraph(graph, data, opts);
// Adding the graph shouldn't cause the width of the page to change.
// (essentially, we're checking that we don't end up with a scrollbar)
// See http://stackoverflow.com/a/2146905/388951
assert.equal(cw, document.body.clientWidth);
assert.equal(sw, document.body.scrollWidth);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment