-
-
Notifications
You must be signed in to change notification settings - Fork 426
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
Ahmed Hussein
committed
Jul 3, 2024
1 parent
8552d7e
commit 9629df3
Showing
3 changed files
with
87 additions
and
44 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
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
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,39 @@ | ||
import { it, expect } from 'vitest'; | ||
|
||
import { uniqueArrayByObjectProperty } from '../../array'; | ||
|
||
it('should return an empty array if the input array is empty', () => { | ||
const input = []; | ||
const output = uniqueArrayByObjectProperty(input, 'id'); | ||
expect(output).toEqual([]); | ||
}); | ||
|
||
it('should return the same array if there are no duplicates', () => { | ||
const input = [{ id: 1 }, { id: 2 }, { id: 3 }]; | ||
const output = uniqueArrayByObjectProperty(input, 'id'); | ||
expect(output).toEqual(input); | ||
}); | ||
|
||
it('should return an array with duplicates removed based on the property', () => { | ||
const input = [{ id: 1 }, { id: 2 }, { id: 1 }, { id: 3 }]; | ||
const output = uniqueArrayByObjectProperty(input, 'id'); | ||
expect(output).toEqual([{ id: 1 }, { id: 2 }, { id: 3 }]); | ||
}); | ||
|
||
it('should handle different property names correctly', () => { | ||
const input = [{ name: 'Alice' }, { name: 'Bob' }, { name: 'Alice' }]; | ||
const output = uniqueArrayByObjectProperty(input, 'name'); | ||
expect(output).toEqual([{ name: 'Alice' }, { name: 'Bob' }]); | ||
}); | ||
|
||
it('should handle objects that do not have the specified property correctly', () => { | ||
const input = [{ id: 1 }, { name: 'Bob' }, { id: 1 }, { id: 2 }]; | ||
const output = uniqueArrayByObjectProperty(input, 'id'); | ||
expect(output).toEqual([{ id: 1 }, { name: 'Bob' }, { id: 2 }]); | ||
}); | ||
|
||
it('should handle arrays with different types of data correctly', () => { | ||
const input = [{ id: 1 }, 2, { id: 1 }, 'test', { id: 2 }, 'test']; | ||
const output = uniqueArrayByObjectProperty(input, 'id'); | ||
expect(output).toEqual([{ id: 1 }, 2, 'test', { id: 2 }]); | ||
}); |