Skip to content

Commit

Permalink
[test] [minor] Improving test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Oct 27, 2018
1 parent 8f032d2 commit 3f7ff55
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
37 changes: 36 additions & 1 deletion test/address.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,26 @@ describe("address.js", function () {
faker.address.direction.restore();
})

it("returns abbreviation when useAbbr is true", function () {
it("returns abbreviation when useAbbr is false", function () {
sinon.stub(faker.address, 'direction').returns('N');
var direction = faker.address.direction(false);
assert.equal(direction, 'N');
faker.address.direction.restore();
})

it("returns abbreviation when useAbbr is true", function () {
var direction = faker.address.direction(true);
assert.equal(typeof direction, 'string');
assert.equal(direction.length <= 2, true);
})

it("returns abbreviation when useAbbr is true", function () {
sinon.stub(faker.address, 'direction').returns('N');
var direction = faker.address.direction(true);
assert.equal(direction, 'N');
faker.address.direction.restore();
})

})

describe("ordinalDirection()", function () {
Expand All @@ -406,6 +419,14 @@ describe("address.js", function () {
assert.equal(ordinalDirection, 'W');
faker.address.ordinalDirection.restore();
})

it("returns abbreviation when useAbbr is true", function () {
var ordinalDirection = faker.address.ordinalDirection(true);
assert.equal(typeof ordinalDirection, 'string');
assert.equal(ordinalDirection.length <= 2, true);
})


})

describe("cardinalDirection()", function () {
Expand All @@ -424,6 +445,13 @@ describe("address.js", function () {
assert.equal(cardinalDirection, 'NW');
faker.address.cardinalDirection.restore();
})

it("returns abbreviation when useAbbr is true", function () {
var cardinalDirection = faker.address.cardinalDirection(true);
assert.equal(typeof cardinalDirection, 'string');
assert.equal(cardinalDirection.length <= 2, true);
})

})

describe("nearbyGPSCoordinate()", function () {
Expand Down Expand Up @@ -471,6 +499,13 @@ describe("address.js", function () {
var actualDistance = haversine(latFloat1, lonFloat1, latFloat2, lonFloat2, isMetric);
assert.ok(actualDistance <= (radius + error));
}

// test once with undefined radius
var coordinate = faker.address.nearbyGPSCoordinate([latFloat1, lonFloat1], undefined, isMetric);
assert.ok(coordinate.length === 2);
assert.ok(typeof coordinate[0] === 'string');
assert.ok(typeof coordinate[1] === 'string');

});
});

Expand Down
7 changes: 6 additions & 1 deletion test/name.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ describe("name.js", function () {

it("returns male prefix", function () {
var prefix = faker.name.prefix(0);

assert.equal(prefix, 'Mp')
});

Expand All @@ -172,6 +171,12 @@ describe("name.js", function () {

assert.equal(prefix, 'Fp');
});

it("returns either prefix", function () {
var prefix = faker.name.prefix();
assert(['Mp', 'Fp'].indexOf(prefix) >= 0)
});

});

describe('when using a locale without gender specific name prefixes', function () {
Expand Down

0 comments on commit 3f7ff55

Please sign in to comment.