Fix: Stringify append and prepend values

This commit is contained in:
Robin Bijlani
2019-07-25 13:12:07 +08:00
committed by Jun Yang
parent 49c45a463b
commit c8c6dd8275
2 changed files with 12 additions and 3 deletions
+2 -2
View File
@@ -6,8 +6,8 @@
import { stringify } from '../../util/underscore'
export default {
'append': (v: string, arg: string) => stringify(v) + arg,
'prepend': (v: string, arg: string) => arg + stringify(v),
'append': (v: string, arg: string) => stringify(v) + stringify(arg),
'prepend': (v: string, arg: string) => stringify(arg) + stringify(v),
'capitalize': capitalize,
'lstrip': (v: string) => stringify(v).replace(/^\s+/, ''),
'downcase': (v: string) => stringify(v).toLowerCase(),
+10 -1
View File
@@ -10,7 +10,16 @@ describe('filters/string', function () {
describe('append', function () {
it('should return "-3abc" for -3, "abc"',
() => test('{{ -3 | append: "abc" }}', '-3abc'))
it('should return "abar" for "a",foo', () => test('{{ "a" | append: foo }}', 'abar'))
it('should return "abar" for "a", foo', () => test('{{ "a" | append: foo }}', 'abar'))
it('should return "abc" for "abc", undefined', () => test('{{ "abc" | append: undefinedVar }}', 'abc'))
it('should return "abcfalse" for "abc", false', () => test('{{ "abc" | append: false }}', 'abcfalse'))
})
describe('prepend', function () {
it('should return "-3abc" for -3, "abc"',
() => test('{{ -3 | prepend: "abc" }}', 'abc-3'))
it('should return "abar" for "a", foo', () => test('{{ "a" | prepend: foo }}', 'bara'))
it('should return "abc" for "abc", undefined', () => test('{{ "abc" | prepend: undefinedVar }}', 'abc'))
it('should return "falseabc" for "abc", false', () => test('{{ "abc" | prepend: false }}', 'falseabc'))
})
describe('capitalize', function () {
it('should capitalize first', async () => {