Browse Source

Allow string templates to handle null objects without failing

gh-pages
Andrew Kingston 5 years ago
parent
commit
7e082a18d8
  1. 3
      packages/string-templates/src/index.cjs
  2. 4
      packages/string-templates/test/basic.spec.js

3
packages/string-templates/src/index.cjs

@ -16,9 +16,6 @@ registerAll(hbsInstance)
* utility function to check if the object is valid * utility function to check if the object is valid
*/ */
function testObject(object) { function testObject(object) {
if (object == null) {
throw "Unable to process null object"
}
// JSON stringify will fail if there are any cycles, stops infinite recursion // JSON stringify will fail if there are any cycles, stops infinite recursion
try { try {
JSON.stringify(object) JSON.stringify(object)

4
packages/string-templates/test/basic.spec.js

@ -81,14 +81,14 @@ describe("Test that the object processing works correctly", () => {
expect(error).not.toBeNull() expect(error).not.toBeNull()
}) })
it("should fail gracefully when wrong type is passed in", async () => { it("should be able to handle null objects", async () => {
let error = null let error = null
try { try {
await processObject(null, null) await processObject(null, null)
} catch (err) { } catch (err) {
error = err error = err
} }
expect(error).not.toBeNull() expect(error).toBeNull()
}) })
}) })

Loading…
Cancel
Save