Sha256: a10b29abc600dbcc4ed1cef876d42a09cd6e0fe61035c3d04cb85951059c8c41

Contents?: true

Size: 1.54 KB

Versions: 71

Compression:

Stored size: 1.54 KB

Contents

import PhoneNumber from './phone-number'

describe('PhoneNumber()', () => {

  it('cleans the number', () => {
    const phone = new PhoneNumber('(123) 456-7890')
    expect(phone.number()).toEqual('1234567890')
  })

  it('cleans numbers with dots', () => {
    const phone = new PhoneNumber('123.456.7890')
    expect(phone.number()).toEqual('1234567890')
  })

  it('cleans numbers with multiple spaces', () => {
    const phone = new PhoneNumber('123 456   7890   ')
    expect(phone.number()).toEqual('1234567890')
  })

  it('invalid when 9 digits', () => {
    const phone = new PhoneNumber('123456789')
    expect(phone.number()).toEqual(undefined)
  })

  it('invalid when 11 digits', () => {
    const phone = new PhoneNumber('21234567890')
    expect(phone.number()).toEqual(undefined)
  })

  it('valid when 11 digits and starting with 1', () => {
    const phone = new PhoneNumber('11234567890')
    expect(phone.number()).toEqual('1234567890')
  })

  it('invalid when 12 digits', () => {
    const phone = new PhoneNumber('321234567890')
    expect(phone.number()).toEqual(undefined)
  })

  it('invalid with letters', () => {
    const phone = new PhoneNumber('123-abc-7890')
    expect(phone.number()).toEqual(undefined)
  })

  it('invalid with punctuations', () => {
    const phone = new PhoneNumber('123-@:!-7890')
    expect(phone.number()).toEqual(undefined)
  })

  it('invalid with right number of digits but letters mixed in', () => {
    const phone = new PhoneNumber('1a2b3c4d5e6f7g8h9i0j')
    expect(phone.number()).toEqual(undefined)
  })

})

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
trackler-2.1.0.16 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.15 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.14 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.13 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.12 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.11 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.10 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.9 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.8 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.7 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.6 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.5 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.4 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.3 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.2 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.1 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.1.0.0 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.0.8.55 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.0.8.54 tracks/typescript/exercises/phone-number/phone-number.test.ts
trackler-2.0.8.53 tracks/typescript/exercises/phone-number/phone-number.test.ts