all files / src/__tests__/ format-message.spec.js

100% Statements 20/20
100% Branches 4/4
100% Functions 6/6
100% Lines 18/18
1 branch Ignored     
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                
import assert from 'assert'
import { formatMsg } from '../helpers'
 
 
describe('formatMessage', function() {
  it('should return the default value or id', function() {
    assert.equal('foo', formatMsg({ defaultMessage: 'foo', id: 'bar' }))
    assert.equal('bar', formatMsg({ id: 'bar' }))
  })
  it('should handle FormattedMessage obj', function() {
    assert.equal('foo', formatMsg({ props: { defaultMessage: 'foo', id: 'bar' } }))
  })
  it('should replace the vars', function() {
    assert.equal('foo 1 2', formatMsg({ defaultMessage: 'foo {bar} {foobar}', values: { bar: 1, foobar: 2 } }))
    assert.equal('foo 1', formatMsg({ defaultMessage: 'foo {count, number}', values: { count: 1 } }))
  })
  it('should pluralize', function() {
    let msg = '{count, number} {count, plural, one {char} other {chars}}'
    assert.equal('0 chars', formatMsg({ defaultMessage: msg, values: { count: 0 } }))
    assert.equal('1 char', formatMsg({ defaultMessage: msg, values: { count: 1 } }))
    assert.equal('9 chars', formatMsg({ defaultMessage: msg, values: { count: 9 } }))
    assert.equal('1 char1 char', formatMsg({ defaultMessage: msg + msg, values: { count: 1 } }))
  })
})