From: Simon Brunel Date: Mon, 25 Apr 2016 23:30:59 +0000 (+0200) Subject: New toBeCloseToPixel jasmine matcher X-Git-Tag: 2.1.0~13^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b156bdc98613671d6c4e247b604c89506e3c810;p=thirdparty%2FChart.js.git New toBeCloseToPixel jasmine matcher Because of differences between testing platforms, introduce a new matcher for (floating) pixel values comparison (currently 2 pixels tolerance). --- diff --git a/test/mockContext.js b/test/mockContext.js index 17d9ad5d8..08d6101aa 100644 --- a/test/mockContext.js +++ b/test/mockContext.js @@ -122,6 +122,25 @@ return new Context(); }; + // Custom matcher + function toBeCloseToPixel() { + return { + compare: function(actual, expected) { + var result = (!isNaN(actual) && !isNaN(expected))? + Math.abs(actual - expected) < 2 : // 2 pixels tolerance + false; + + return { pass: result }; + } + } + }; + + window.addDefaultMatchers = function(jasmine) { + jasmine.addMatchers({ + toBeCloseToPixel: toBeCloseToPixel + }); + } + // Canvas injection helpers var charts = {};