Skip to content

Commit

Permalink
adds ability to get random country code and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
FotoVerite committed Oct 27, 2014
1 parent c109b48 commit 4a5de1a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports.definitions = {};

var _definitions = {
"name": ["first_name", "last_name", "prefix", "suffix"],
"address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "state", "state_abbr"],
"address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "state", "state_abbr"],
"company": ["adjective", "noun", "descriptor", "bs_adjective", "bs_noun", "bs_verb"],
"lorem": ["words"],
"hacker": ["abbreviation", "adjective", "noun", "verb", "ingverb"],
Expand Down
4 changes: 4 additions & 0 deletions lib/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ var address = {
return faker.random.array_element(faker.definitions.address.country);
},

countryCode: function () {
return faker.random.array_element(faker.definitions.address.country_code);
},

state: function (useAbbr) {
return faker.random.array_element(faker.definitions.address.state);
},
Expand Down
18 changes: 14 additions & 4 deletions test/address.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("address.js", function () {
assert.ok(faker.address.citySuffix.calledOnce);
});
});


describe("streetName()", function () {
beforeEach(function () {
Expand Down Expand Up @@ -100,8 +100,8 @@ describe("address.js", function () {
assert.ok(faker.address.streetSuffix.calledOnce);
});
});



describe("streetAddress()", function () {
beforeEach(function () {
Expand Down Expand Up @@ -157,7 +157,7 @@ describe("address.js", function () {
});
});
});


describe("secondaryAddress()", function () {
it("randomly chooses an Apt or Suite number", function () {
Expand Down Expand Up @@ -196,6 +196,16 @@ describe("address.js", function () {
});
});

describe("countryCode()", function () {
it("returns random countryCode", function () {
sinon.spy(faker.address, 'countryCode');
var countryCode = faker.address.countryCode();
assert.ok(countryCode);
assert.ok(faker.address.countryCode.called);
faker.address.countryCode.restore();
});
});

describe("state()", function () {
it("returns random state", function () {
sinon.spy(faker.address, 'state');
Expand Down

0 comments on commit 4a5de1a

Please sign in to comment.