Skip to content

Commit

Permalink
fix(matchers): allow integers/decimals to be 0 (#236)
Browse files Browse the repository at this point in the history
Due to how javascript deals with 0 in if statements passing 0 into `integer()/decimal()` results in
the default value 13. This change corrects that by doing a nil check instead
  • Loading branch information
James Gee authored and mefellows committed Oct 27, 2018
1 parent 48d5cbd commit c40ce32
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/dsl/matchers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ describe("Matcher", () => {
it("should not fail", () => {
expect(decimal(10.1)).to.be.an("object");
expect(decimal()).to.be.an("object");
expect(decimal(0.00).contents).to.equal(0.00);
});
});
});
Expand All @@ -430,6 +431,7 @@ describe("Matcher", () => {
it("should not fail", () => {
expect(integer(10)).to.be.an("object");
expect(integer()).to.be.an("object");
expect(integer(0).contents).to.equal(0);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/dsl/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ export function hexadecimal(hex?: string) {
* @param {float} float - a decimal value.
*/
export function decimal(float?: number) {
return somethingLike<number>(float || 13.01);
return somethingLike<number>(isNil(float) ? 13.01 : float);
}

/**
* Integer Matcher.
* @param {integer} int - an int value.
*/
export function integer(int?: number) {
return somethingLike<number>(int || 13);
return somethingLike<number>(isNil(int) ? 13 : int);
}

/**
Expand Down

0 comments on commit c40ce32

Please sign in to comment.