Created
February 12, 2016 01:18
-
-
Save teone/2b95ccd2ced6a256d5bd to your computer and use it in GitHub Desktop.
Jasmine Custom Matcher - toBeSimilar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // test that numbers are similar with a tolerance of 0.1 | |
| var customMatchers = { | |
| toBeSimilar: (util, tester) => { | |
| const tolerance = 0.1; | |
| return { | |
| compare: (actual, expected) => { | |
| return { | |
| pass: (Math.abs(actual - expected) < tolerance), | |
| message: `Expected ${actual} to be ${expected}` | |
| } | |
| } | |
| } | |
| } | |
| }; | |
| beforeEach(function() { | |
| jasmine.addMatchers(customMatchers); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment