Skip to content

Commit

Permalink
add test for custom random function
Browse files Browse the repository at this point in the history
  • Loading branch information
eumkz committed Jul 3, 2024
1 parent 84adbfc commit 3b8da79
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/random/shuffle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ describe('shuffle', () => {
expect(list).not.toBe(result)
expect(list).toEqual([1, 2, 3, 4, 5])
})
test('uses custom random function when provided', () => {
const list = [1, 2, 3, 4, 5]
const mockRandom = vi.fn(() => 1)
const result = _.shuffle(list, mockRandom)

expect(mockRandom).toHaveBeenCalled()
expect(result).not.toEqual(list)
expect(result.length).toBe(list.length)
expect(new Set(result)).toEqual(new Set(list))
})
})

0 comments on commit 3b8da79

Please sign in to comment.