From c40ce324508a0225f13e7f9909a0d75d107153e0 Mon Sep 17 00:00:00 2001 From: James Gee Date: Sat, 27 Oct 2018 06:30:35 +0100 Subject: [PATCH] fix(matchers): allow integers/decimals to be 0 (#236) 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 --- src/dsl/matchers.spec.ts | 2 ++ src/dsl/matchers.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/dsl/matchers.spec.ts b/src/dsl/matchers.spec.ts index 221ca7890..79c2b1267 100644 --- a/src/dsl/matchers.spec.ts +++ b/src/dsl/matchers.spec.ts @@ -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); }); }); }); @@ -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); }); }); }); diff --git a/src/dsl/matchers.ts b/src/dsl/matchers.ts index 5634a9280..85484c9a2 100644 --- a/src/dsl/matchers.ts +++ b/src/dsl/matchers.ts @@ -171,7 +171,7 @@ export function hexadecimal(hex?: string) { * @param {float} float - a decimal value. */ export function decimal(float?: number) { - return somethingLike(float || 13.01); + return somethingLike(isNil(float) ? 13.01 : float); } /** @@ -179,7 +179,7 @@ export function decimal(float?: number) { * @param {integer} int - an int value. */ export function integer(int?: number) { - return somethingLike(int || 13); + return somethingLike(isNil(int) ? 13 : int); } /**