diff --git a/index.js b/index.js index f3bc4291b..92182c440 100644 --- a/index.js +++ b/index.js @@ -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"], diff --git a/lib/address.js b/lib/address.js index 6a9e3beb3..6daf981ae 100644 --- a/lib/address.js +++ b/lib/address.js @@ -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); }, diff --git a/test/address.unit.js b/test/address.unit.js index b03a3be4e..f6b299a12 100644 --- a/test/address.unit.js +++ b/test/address.unit.js @@ -63,7 +63,7 @@ describe("address.js", function () { assert.ok(faker.address.citySuffix.calledOnce); }); }); - + describe("streetName()", function () { beforeEach(function () { @@ -100,8 +100,8 @@ describe("address.js", function () { assert.ok(faker.address.streetSuffix.calledOnce); }); }); - - + + describe("streetAddress()", function () { beforeEach(function () { @@ -157,7 +157,7 @@ describe("address.js", function () { }); }); }); - + describe("secondaryAddress()", function () { it("randomly chooses an Apt or Suite number", function () { @@ -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');