]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
New toBeCloseToPixel jasmine matcher
authorSimon Brunel <simonbrunel@users.noreply.github.com>
Mon, 25 Apr 2016 23:30:59 +0000 (01:30 +0200)
committerSimon Brunel <simonbrunel@users.noreply.github.com>
Tue, 26 Apr 2016 10:46:33 +0000 (12:46 +0200)
Because of differences between testing platforms, introduce a new matcher for (floating) pixel values comparison (currently 2 pixels tolerance).

test/mockContext.js

index 17d9ad5d8fbe91c4c6145e73d1e30a72741fc9a7..08d6101aa9e376bd4708f6b17bd51c02d9910a22 100644 (file)
                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 = {};