Skip to content

Instantly share code, notes, and snippets.

@teone
Created February 12, 2016 01:18
Show Gist options
  • Select an option

  • Save teone/2b95ccd2ced6a256d5bd to your computer and use it in GitHub Desktop.

Select an option

Save teone/2b95ccd2ced6a256d5bd to your computer and use it in GitHub Desktop.
Jasmine Custom Matcher - toBeSimilar
// 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