test cases for stringify

This commit is contained in:
harttle
2018-08-14 00:11:50 +08:00
committed by Jun Yang
parent 7a3689067b
commit 887b736f39
2 changed files with 14 additions and 6 deletions
+8 -6
View File
@@ -11,12 +11,14 @@ function isString (value) {
} }
function stringify (value) { function stringify (value) {
if (!isNil(value)) { if (isNil(value)) {
if (typeof value.to_liquid === 'function') { return String(value)
return stringify(value.to_liquid()) }
} else if (typeof value.toLiquid === 'function') { if (typeof value.to_liquid === 'function') {
return stringify(value.toLiquid()) return stringify(value.to_liquid())
} }
if (typeof value.toLiquid === 'function') {
return stringify(value.toLiquid())
} }
if (isString(value)) { if (isString(value)) {
return value return value
+6
View File
@@ -44,6 +44,12 @@ describe('util/underscore', function () {
it('should recursively call toLiquid()', function () { it('should recursively call toLiquid()', function () {
expect(_.stringify({toLiquid: () => ({toLiquid: () => 'foo'})})).to.equal('foo') expect(_.stringify({toLiquid: () => ({toLiquid: () => 'foo'})})).to.equal('foo')
}) })
it('should return "null" for null', function () {
expect(_.stringify(null)).to.equal('null')
})
it('should return "undefined" for undefined', function () {
expect(_.stringify(undefined)).to.equal('undefined')
})
}) })
describe('.forOwn()', function () { describe('.forOwn()', function () {
it('should iterate all properties', function () { it('should iterate all properties', function () {