Skip to content

Commit

Permalink
fix: add null as extra instead of detail (#56)
Browse files Browse the repository at this point in the history
`null` should always have been an extra, but was not due to it being marked as an `object` type in JS/TS.
  • Loading branch information
jdbruijn authored Apr 22, 2022
1 parent 8656303 commit 2533c01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/formatter/extras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class Extras {
* @returns `true` if the key-value was valid and is added, false otherwise.
*/
parseAndAdd(key: string, value: unknown): boolean {
if (typeof value === 'object' || typeof value === 'function') {
if (
(typeof value === 'object' && value !== null) ||
typeof value === 'function'
) {
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/formatter/extras.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ describe('Extras', () => {
expect(extras.extras).toHaveLength(0);
extras.parseAndAdd('myKey', 'myValue');
expect(extras.extras).toHaveLength(1);
extras.parseAndAdd('otherKey', null);
expect(extras.extras).toHaveLength(2);
});

it('does not add the extra if it is invalid', () => {
Expand Down

0 comments on commit 2533c01

Please sign in to comment.