Files
jasmine/spec/core/matchers/toBeCloseToSpec.js
Sheel Choksi 39d7ebf28e Remove an extra layer of wrapping for matchers/custom matchers
Helps reduce how nested custom matchers have to be for users as well as
Jasmine internal matchers

[#59161378]
2013-10-20 22:21:56 -07:00

52 lines
1.4 KiB
JavaScript

describe("toBeCloseTo", function() {
it("passes when within two decimal places by default", function() {
var matcherComparator = j$.matchers.toBeCloseTo(),
result;
result = matcherComparator(0, 0);
expect(result.pass).toBe(true);
result = matcherComparator(0, 0.001);
expect(result.pass).toBe(true);
});
it("fails when not within two decimal places by default", function() {
var matcherComparator = j$.matchers.toBeCloseTo(),
result;
result = matcherComparator(0, 0.01);
expect(result.pass).toBe(false);
});
it("accepts an optional precision argument", function() {
var matcherComparator = j$.matchers.toBeCloseTo(),
result;
result = matcherComparator(0, 0.1, 0);
expect(result.pass).toBe(true);
result = matcherComparator(0, 0.0001, 3);
expect(result.pass).toBe(true);
});
it("rounds expected values", function() {
var matcherComparator = j$.matchers.toBeCloseTo(),
result;
result = matcherComparator(1.23, 1.229);
expect(result.pass).toBe(true);
result = matcherComparator(1.23, 1.226);
expect(result.pass).toBe(true);
result = matcherComparator(1.23, 1.225);
expect(result.pass).toBe(true);
result = matcherComparator(1.23, 1.2249999);
expect(result.pass).toBe(false);
result = matcherComparator(1.23, 1.234);
expect(result.pass).toBe(true);
});
});