diff --git a/lib/delta.js b/lib/delta.js index cd52128..b36a50e 100644 --- a/lib/delta.js +++ b/lib/delta.js @@ -23,7 +23,7 @@ Delta.prototype.insert = function (text, attributes) { var newOp = {}; if (text.length === 0) return this; newOp.insert = text; - if (typeof attributes === 'object' && Object.keys(attributes).length > 0) newOp.attributes = attributes; + if (attributes instanceof Object && Object.keys(attributes).length > 0) newOp.attributes = attributes; return this.push(newOp); }; @@ -35,7 +35,7 @@ Delta.prototype['delete'] = function (length) { Delta.prototype.retain = function (length, attributes) { if (length <= 0) return this; var newOp = { retain: length }; - if (typeof attributes === 'object' && Object.keys(attributes).length > 0) newOp.attributes = attributes; + if (attributes instanceof Object && Object.keys(attributes).length > 0) newOp.attributes = attributes; return this.push(newOp); }; diff --git a/test/delta/builder.js b/test/delta/builder.js index d922fef..d956211 100644 --- a/test/delta/builder.js +++ b/test/delta/builder.js @@ -49,6 +49,12 @@ describe('insert()', function () { expect(delta.ops[0]).toEqual({ insert: 'test' }); }); + it('insert(text, null)', function () { + var delta = new Delta().insert('test', null); + expect(delta.ops.length).toEqual(1); + expect(delta.ops[0]).toEqual({ insert: 'test' }); + }); + it('insert(embed)', function () { var delta = new Delta().insert(1); expect(delta.ops.length).toEqual(1); @@ -132,6 +138,12 @@ describe('retain()', function () { expect(delta.ops[0]).toEqual({ retain: 2 }); }); + it('retain(length, null)', function () { + var delta = new Delta().retain(2, null); + expect(delta.ops.length).toEqual(1); + expect(delta.ops[0]).toEqual({ retain: 2 }); + }); + it('retain(length, attributes)', function () { var delta = new Delta().retain(1, { bold: true }); expect(delta.ops.length).toEqual(1);