forked from bengourley/currency-symbol-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
29 lines (25 loc) · 1.34 KB
/
test.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
const test = require('tape')
const getSymbolFromCurrency = require('./')
const currencySymbolMap = require('./map')
test('getSymbolFromCurrency(): valid params', t => {
t.equal('$', getSymbolFromCurrency('USD'), 'should return $ when USD is provided')
t.equal('£', getSymbolFromCurrency('GBP'), 'should return £ when GBP is provided')
t.equal('€', getSymbolFromCurrency('EUR'), 'should return € when EUR is provided')
t.equal('€', getSymbolFromCurrency('eur'), 'should return € when eur is provided')
t.equal(undefined, getSymbolFromCurrency('NON-EXISTENT-CODE'), 'should return undefined when code is non-existent')
t.end()
})
test('getSymbolFromCurrency(): invalid params', t => {
t.equal(undefined, getSymbolFromCurrency(1), 'should return undefined when param is not a string')
t.equal(undefined, getSymbolFromCurrency(null), 'should return undefined when param is null')
t.equal(undefined, getSymbolFromCurrency(false), 'should return undefined when param is false')
t.equal(undefined, getSymbolFromCurrency(), 'should return undefined when param is undefined')
t.end()
})
test('currency-symbol-map: sanity check every value in map', t => {
const currencies = Object.keys(currencySymbolMap)
const obj = {}
currencies.forEach(code => { obj[code] = getSymbolFromCurrency(code) })
t.deepEqual(obj, currencySymbolMap)
t.end()
})