diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/address.unit.js | 99 | ||||
| -rw-r--r-- | test/all.functional.js | 41 | ||||
| -rw-r--r-- | test/locales.unit.js | 9 | ||||
| -rw-r--r-- | test/phone_number.unit.js | 13 |
4 files changed, 50 insertions, 112 deletions
diff --git a/test/address.unit.js b/test/address.unit.js index b87a3ea1..b03a3be4 100644 --- a/test/address.unit.js +++ b/test/address.unit.js @@ -176,97 +176,36 @@ describe("address.js", function () { }); }); - - describe("brState()", function () { - beforeEach(function () { - sinon.spy(faker.address, 'brStateAbbr'); - sinon.spy(faker.address, 'brState'); - }); - - afterEach(function () { - faker.address.brStateAbbr.restore(); - faker.address.brState.restore(); - }); - - context("when useAbbr is true", function () { - it("returns a brStateAbbr", function () { - var state = faker.address.brStateAbbr(true); - - assert.ok(state); - assert.ok(faker.address.brStateAbbr.called); - assert.ok(!faker.address.brState.called); - }); - }); - - context("when useAbbr is not set", function () { - it("returns a brState", function () { - var state = faker.address.brState(); - - assert.ok(state); - assert.ok(!faker.address.brStateAbbr.called); - assert.ok(faker.address.brState.called); - }); - }); - }); - - - - describe("ukCounty()", function () { - it("returns random uk_county", function () { - sinon.spy(faker.address, 'ukCounty'); - var county = faker.address.ukCounty(); + describe("county()", function () { + it("returns random county", function () { + sinon.spy(faker.address, 'county'); + var county = faker.address.county(); assert.ok(county); - assert.ok(faker.address.ukCounty.called); - faker.address.ukCounty.restore(); + assert.ok(faker.address.county.called); + faker.address.county.restore(); }); }); - describe("ukCountry()", function () { - it("returns random ukCountry", function () { - sinon.spy(faker.address, 'ukCountry'); - var country = faker.address.ukCountry(); + describe("country()", function () { + it("returns random country", function () { + sinon.spy(faker.address, 'country'); + var country = faker.address.country(); assert.ok(country); - assert.ok(faker.address.ukCountry.called); - faker.address.ukCountry.restore(); + assert.ok(faker.address.country.called); + faker.address.country.restore(); }); }); - - describe("usState()", function () { - beforeEach(function () { - sinon.spy(faker.address, 'usStateAbbr'); - sinon.spy(faker.address, 'usState'); - }); - - afterEach(function () { - faker.address.usStateAbbr.restore(); - faker.address.usState.restore(); - }); - - /* - context("when useAbbr is true", function () { - it("returns a usStateAbbr", function () { - var state = faker.address.usState(true); - - assert.ok(state); - assert.ok(faker.address.usStateAbbr.called); - assert.ok(!faker.address.usState.called); - }); - }); - - context("when useAbbr is not set", function () { - it("returns a usState", function () { - var state = faker.address.usState(); - - assert.ok(state); - assert.ok(!faker.address.usStateAbbr.called); - assert.ok(faker.address.usState.called); - }); + describe("state()", function () { + it("returns random state", function () { + sinon.spy(faker.address, 'state'); + var state = faker.address.state(); + assert.ok(state); + assert.ok(faker.address.state.called); + faker.address.state.restore(); }); - */ }); - describe("latitude()", function () { it("returns random latitude", function () { for (var i = 0; i < 100; i++) { diff --git a/test/all.functional.js b/test/all.functional.js index 621b9fd9..02b801ac 100644 --- a/test/all.functional.js +++ b/test/all.functional.js @@ -9,7 +9,7 @@ if (typeof module !== 'undefined') { var modules = { address: [ 'city', 'streetName', 'streetAddress', 'secondaryAddress', - 'brState', 'ukCountry', 'ukCounty', 'usState', 'zipCode' + 'country', 'county', 'state', 'zipCode' ], company: ['companyName', 'companySuffix', 'catchPhrase', 'bs'], @@ -20,28 +20,23 @@ var modules = { name: ['firstName', 'lastName', 'findName'], - phoneNumber: ['phoneNumber'] + phone: ['phoneNumber'] }; describe("functional tests", function () { - Object.keys(modules).forEach(function (module) { - describe(module, function () { - modules[module].forEach(function (meth) { - it(meth + "()", function () { - var result = faker[module][meth](); - assert.ok(result); - }); - }); - }); - }); - - describe("Address", function () { - it("zipCodeFormat()", function () { - var result = faker.address.zipCodeFormat(0); - assert.ok(!result.match(/-/)); - - result = faker.address.zipCodeFormat(1); - assert.ok(result.match(/-/)); - }); - }); -}); + + for(var locale in faker.locales) { + faker.locale = locale; + Object.keys(modules).forEach(function (module) { + describe(module, function () { + modules[module].forEach(function (meth) { + it(meth + "()", function () { + var result = faker[module][meth](); + assert.ok(result); + }); + }); + }); + }); + } + +});
\ No newline at end of file diff --git a/test/locales.unit.js b/test/locales.unit.js new file mode 100644 index 00000000..0b2d4175 --- /dev/null +++ b/test/locales.unit.js @@ -0,0 +1,9 @@ +if (typeof module !== 'undefined') { + var assert = require('assert'); + var sinon = require('sinon'); + var faker = require('../index'); +} + +// TODO: make some tests for getting / setting locales + +// Remark: actual use of locales functionality is currently tested in all.functional.js test
\ No newline at end of file diff --git a/test/phone_number.unit.js b/test/phone_number.unit.js index e4697a30..4764c87b 100644 --- a/test/phone_number.unit.js +++ b/test/phone_number.unit.js @@ -8,7 +8,7 @@ describe("phone_number.js", function () { describe("phoneNumber()", function () { it("returns a random phoneNumber with a random format", function () { sinon.spy(faker.helpers, 'replaceSymbolWithNumber'); - var phone_number = faker.phoneNumber.phoneNumber(); + var phone_number = faker.phone.phoneNumber(); assert.ok(phone_number.match(/\d/)); assert.ok(faker.helpers.replaceSymbolWithNumber.called); @@ -20,16 +20,11 @@ describe("phone_number.js", function () { describe("phoneNumberFormat()", function () { it("returns phone number with requested format (Array index)", function () { for (var i = 0; i < 10; i++) { - var phone_number = faker.phoneNumber.phoneNumberFormat(5); - assert.ok(phone_number.match(/\(\d\d\d\)\d\d\d-\d\d\d\d/)); + var phone_number = faker.phone.phoneNumberFormat(1); + assert.ok(phone_number.match(/\(\d\d\d\) \d\d\d-\d\d\d\d/)); } }); }); - describe("phoneCode()", function () { - it("returns a phone code with a format +xx", function () { - var phone_code = faker.phoneNumber.phoneCode(); - assert.ok(phone_code.match(/^\+\d{1,3}$/)); - }); - }); + }); |
