Clean up phone number formatting (#1015)

This commit is contained in:
Fahim Faisaal
2022-05-16 22:48:16 +06:00
committed by GitHub
parent f736217341
commit c865654f27
2 changed files with 21 additions and 30 deletions

View File

@ -1,23 +1,15 @@
import { formatPhoneNumber } from '../FormatPhoneNumber'
import formatPhoneNumber from '../FormatPhoneNumber'
describe('PhoneNumberFormatting', () => {
it('expects to return the formatted phone number', () => {
expect(formatPhoneNumber('1234567890')).toEqual('(123) 456-7890')
describe('Testing the formatPhoneNumber functions', () => {
it('expects to throw a type error', () => {
expect(() => formatPhoneNumber('1234567')).toThrow('Invalid phone number!')
expect(() => formatPhoneNumber('123456text')).toThrow('Invalid phone number!')
expect(() => formatPhoneNumber(12345)).toThrow('Invalid phone number!')
})
it('expects to return the formatted phone number', () => {
expect(formatPhoneNumber(1234567890)).toEqual('(123) 456-7890')
})
it('expects to throw a type error', () => {
expect(() => { formatPhoneNumber('1234567') }).toThrow('Invalid phone number.')
})
it('expects to throw a type error', () => {
expect(() => { formatPhoneNumber('123456text') }).toThrow('Invalid phone number.')
})
it('expects to throw a type error', () => {
expect(() => { formatPhoneNumber(12345) }).toThrow('Invalid phone number.')
expect(formatPhoneNumber('1234567890')).toEqual('(123) 456-7890')
expect(formatPhoneNumber('2124323322')).toEqual('(212) 432-3322')
expect(formatPhoneNumber('1721543455')).toEqual('(172) 154-3455')
})
})