mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-11-22 01:36:56 +01:00
Add tests for format_text.js
This commit adds tests for format_text, with the aim to improve the code coverage of the whole repo. Part of https://github.com/bigchaindb/js-bigchaindb-driver/issues/220
This commit is contained in:
parent
aaad21895f
commit
64713d3742
48
test/text-format/test_format_text.js
Normal file
48
test/text-format/test_format_text.js
Normal file
@ -0,0 +1,48 @@
|
||||
import test from 'ava'
|
||||
import formatText from '../../src/format_text'
|
||||
|
||||
test('formatText test type 1', t => {
|
||||
const expected = 'Hi there Dimi!'
|
||||
const actual = formatText('Hi there ${dimi}!', { dimi: 'Dimi' }) // eslint-disable-line no-template-curly-in-string
|
||||
|
||||
t.is(actual, expected)
|
||||
})
|
||||
|
||||
test('formatText test type 2', t => {
|
||||
const expected = 'BigchainDB is big'
|
||||
const actual = formatText('${database} is %(status)s', { // eslint-disable-line no-template-curly-in-string
|
||||
database: 'BigchainDB',
|
||||
status: 'big'
|
||||
})
|
||||
|
||||
t.is(actual, expected)
|
||||
})
|
||||
|
||||
test('formatText test type 3', t => {
|
||||
const expected = 'Berlin is best known for its Currywurst'
|
||||
const actual = formatText(
|
||||
'Berlin is best known for its ${berlin.topKnownFor[0].name}', // eslint-disable-line no-template-curly-in-string
|
||||
{
|
||||
berlin: {
|
||||
topKnownFor: [
|
||||
{
|
||||
name: 'Currywurst'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
t.is(actual, expected)
|
||||
})
|
||||
|
||||
test('formatText test throws', t => {
|
||||
const error = t.throws(() => {
|
||||
formatText(
|
||||
'This will give ${error.}', // eslint-disable-line no-template-curly-in-string
|
||||
{ error: [{}] }
|
||||
)
|
||||
}, SyntaxError)
|
||||
|
||||
t.is(error.message, '[formatText] failed to parse named argument key: error.')
|
||||
})
|
Loading…
Reference in New Issue
Block a user