Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Test.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
open Types
// TODO: mocking etc

/**
* Create mocks with the `mock` function.
*
* ```ts
* import { test, expect, mock } from "bun:test";
* const random = mock(() => Math.random());
*
* test("random", async () => {
* const val = random();
* expect(val).toBeGreaterThan(0);
* expect(random).toHaveBeenCalled();
* expect(random).toHaveBeenCalledTimes(1);
* });
* ```
*/
@module("bun:test")
external mock: (unit => 'value) => unit => 'value = "mock"

/**
* Control the system time used by:
* - `Date.now()`
Expand Down
23 changes: 23 additions & 0 deletions test/Mock.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/Mock.test.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
open Test

let mockFunction = mock(() => ())

describe("mock", () => {
beforeAll(() => {
mockFunction()
})

test("mock function should have been called", () => {
expect(mockFunction->Obj.magic)->Expect.toHaveBeenCalled
mockFunction()
expect(mockFunction->Obj.magic)->Expect.toHaveBeenCalledTimes(2.)
})
})