Skip to content

Commit

Permalink
support null values
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Sep 23, 2023
1 parent 15f3844 commit 63b9777
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/types.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`a null value 1`] = `"__1____2____3__"`;

exports[`a promise-returning function 1`] = `"__1__asdf__2__"`;

exports[`a stream 1`] = `"__1__asdf__2__"`;
Expand Down
9 changes: 9 additions & 0 deletions __tests__/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,12 @@ test('a stream', async () => {
assert.strictEqual(result, '__1__asdf__2__')
expect(result).toMatchSnapshot()
})

test('a null value', async () => {
const promise1 = new Promise(resolve => setImmediate(() => resolve('')))
const promise2 = new Promise(resolve => setImmediate(() => resolve(null)))

const result = await streamToString(render`__1__${promise1}__2__${promise2}__3__`)
assert.strictEqual(result, '__1____2____3__')
expect(result).toMatchSnapshot()
})

Check failure on line 65 in __tests__/types.js

View workflow job for this annotation

GitHub Actions / test (12.x)

Newline required at end of file but not found

Check failure on line 65 in __tests__/types.js

View workflow job for this annotation

GitHub Actions / test (13.x)

Newline required at end of file but not found
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function render (template, ...values) {
}

Promise.resolve(value).then((result) => {
if (!result) return
if (typeof result === 'string') return stream.write(result)
if (result.readableObjectMode) throw new Error('Readable object streams are not supported.')
if (result.readable) return pipe(result)
Expand Down

0 comments on commit 63b9777

Please sign in to comment.