-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { condObject, conditionalObject } from './conditional.js'; | ||
|
||
describe('conditionalObject', () => { | ||
it('should return a new object with all falsy values removed', () => { | ||
const result = conditionalObject({ foo: 'foo', bar: undefined, baz: false } as const); | ||
const result2 = condObject({ foo: 'foo', bar: undefined, baz: false }); | ||
|
||
// @ts-expect-error - `baz` is removed from the object. | ||
type _ = typeof result['baz']; | ||
|
||
// Should be `true | undefined` because `baz` could be true in the original type `boolean`. | ||
type __ = typeof result2['baz']; | ||
|
||
expect(result).toEqual({ foo: 'foo' }); | ||
expect(result2).toEqual({ foo: 'foo' }); | ||
}); | ||
|
||
it('should not remove falsy values nested in objects', () => { | ||
expect(conditionalObject({ foo: 'foo', bar: { baz: false } })).toEqual({ | ||
foo: 'foo', | ||
bar: { baz: false }, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters