UNPKG

@jakguru/phone-object

Version:

An immutable data structure representing a specific phone number and accompanying methods. It contains class and instance methods of creating, parsing, validating, and formatting phone numbers. Based on google-libphonenumber, which is in turn based on Goo

21 lines (19 loc) 784 B
import { test } from '@japa/runner' import { Phone } from '../src/phone' test.group('phone.serialization', () => { test('Able to Serialize and Deserialize a Phone Object', ({ assert }) => { const phone = new Phone('202-456-1414', 'US') assert.equal(phone.raw, '12024561414') assert.equal(phone.country, 'US') const serialized = phone.serialize() assert.isString(serialized) assert.equal( serialized, 'eyJwaG9uZSI6IjEyMDI0NTYxNDE0IiwiY291bnRyeSI6IlVTIiwiaGFzaCI6ImV5SndhRzl1WlNJNklqRXlNREkwTlRZeE5ERTBJaXdpWTI5MWJuUnllU0k2SWxWVEluMD0ifQ==' ) const deserialized = Phone.deserialize(serialized) assert.equal(deserialized.raw, '12024561414') assert.equal(deserialized.country, 'US') assert.deepEqual(phone, deserialized) }) })