-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
01a1373
commit 82a033b
Showing
1 changed file
with
65 additions
and
0 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,65 @@ | ||
/** | ||
* @vitest-environment jsdom | ||
*/ | ||
import { renderHook } from "@testing-library/react"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { type QueueUtility, useQueue } from "./use-queue"; | ||
|
||
describe("useQueue", (): void => { | ||
it("should initialize", (): void => { | ||
const { result } = renderHook((): QueueUtility<number> => useQueue()); | ||
|
||
expect(result.current.queue).toEqual([]); | ||
}); | ||
|
||
it("should initialize with the given value", (): void => { | ||
const { result } = renderHook((): QueueUtility<number> => useQueue([0])); | ||
|
||
expect(result.current.queue).toEqual([0]); | ||
}); | ||
|
||
it("should enqueue a value", (): void => { | ||
const { result, rerender } = renderHook((): QueueUtility<number> => useQueue()); | ||
|
||
result.current.enqueue(0); | ||
|
||
rerender(); | ||
|
||
expect(result.current.queue).toEqual([0]); | ||
}); | ||
|
||
it("should enqueue multiple values", (): void => { | ||
const { result, rerender } = renderHook((): QueueUtility<number> => useQueue()); | ||
|
||
result.current.enqueue(0); | ||
result.current.enqueue(1); | ||
result.current.enqueue(2); | ||
|
||
rerender(); | ||
|
||
expect(result.current.queue).toEqual([0, 1, 2]); | ||
}); | ||
|
||
it("should dequeue a value", (): void => { | ||
const { result, rerender } = renderHook((): QueueUtility<number> => useQueue([0])); | ||
|
||
result.current.dequeue(); | ||
|
||
rerender(); | ||
|
||
expect(result.current.queue).toEqual([]); | ||
}); | ||
|
||
it("should dequeue multiple values", (): void => { | ||
const { result, rerender } = renderHook((): QueueUtility<number> => useQueue([0, 1, 2])); | ||
|
||
result.current.dequeue(); | ||
result.current.dequeue(); | ||
result.current.dequeue(); | ||
|
||
rerender(); | ||
|
||
expect(result.current.queue).toEqual([]); | ||
}); | ||
}); |