diff --git a/src/loggable/due-log.spec.ts b/src/loggable/due-log.spec.ts index c2e9a78..715ffee 100644 --- a/src/loggable/due-log.spec.ts +++ b/src/loggable/due-log.spec.ts @@ -36,6 +36,16 @@ describe('dueLog', () => { it('does not alter raw value', () => { expect(dueLog({ line: [1, 2, 'test'] })).toEqual({ line: [1, 2, 'test'], index: 3 }); }); + it('handles log line element replacement', () => { + + const toLog: Loggable = { + toLog(target) { + target.line[target.index] = logAsTest; + }, + }; + + expect(dueLog({ line: [1, toLog, 2] })).toEqual({ line: [1, 'test', 2], index: 3 }); + }); it('replaces log line element by loggable representation', () => { expect(dueLog({ line: [1, logAsTest, 2] })).toEqual({ line: [1, 'test', 2], index: 3 }); }); diff --git a/src/loggable/due-log.ts b/src/loggable/due-log.ts index 046699e..d599293 100644 --- a/src/loggable/due-log.ts +++ b/src/loggable/due-log.ts @@ -160,7 +160,7 @@ export function dueLog( if (due.index !== index) { due.index = Math.max(due.index, 0); - } else if (due.line === line) { + } else if (due.line === line && line[index] === value) { if (toLog === undefined || toLog === value) { ++due.index; } else if (!isLoggable(toLog) && Array.isArray(toLog)) { diff --git a/src/loggable/loggable.ts b/src/loggable/loggable.ts index d09cd4a..d79501b 100644 --- a/src/loggable/loggable.ts +++ b/src/loggable/loggable.ts @@ -15,9 +15,9 @@ export interface Loggable { * * The method call results interpreted as following: * - * 1. If the method replaced the {@link DueLog.line log line} or updated the next element's {@link DueLog.index - * index}, then the returned value is ignored, and the new log line processing continues from the new element - * index. + * 1. If the method replaced the {@link DueLog.line log line} or currently processed element, or updated the next + * element's {@link DueLog.index index}, then the returned value is ignored, and the new log line processing + * continues from the new element index. * * 2. If the returned value is `undefined` or the same as `this`, then the log line processing continues from the next * element.