forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phone_number.unit.js
48 lines (40 loc) · 1.7 KB
/
phone_number.unit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
if (typeof module !== 'undefined') {
var assert = require('assert');
var sinon = require('sinon');
var faker = require('../index');
}
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.phone.phoneNumber();
assert.ok(phone_number.match(/\d/));
assert.ok(faker.helpers.replaceSymbolWithNumber.called);
faker.helpers.replaceSymbolWithNumber.restore();
});
});
describe("phoneNumberFormat()", function () {
it("returns phone number with requested format (Array index)", function () {
faker.locale = "en";
for (var i = 0; i < 10; i++) {
var phone_number = faker.phone.phoneNumberFormat(1);
assert.ok(phone_number.match(/\(\d\d\d\) \d\d\d-\d\d\d\d/));
}
});
it("returns phone number with proper format US (Array index)", function () {
faker.locale = "en";
for (var i = 0; i < 25; i++) {
var phone_number = faker.phone.phoneNumberFormat(1);
console.log(phone_number)
assert.ok(phone_number.match(/\([2-9]\d\d\) [2-9]\d\d-\d\d\d\d/));
}
});
it("returns phone number with proper format CA (Array index)", function () {
faker.locale = "en_CA";
for (var i = 0; i < 25; i++) {
var phone_number = faker.phone.phoneNumberFormat(1);
assert.ok(phone_number.match(/\([2-9]\d\d\)[2-9]\d\d-\d\d\d\d/));
}
});
});
});