bun-types 1.3.4-canary.20251206T140534 → 1.3.4-canary.20251207T140548
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -60,7 +60,7 @@ test("random", async () => {
|
|
|
60
60
|
|
|
61
61
|
expect(random).toHaveBeenCalled();
|
|
62
62
|
expect(random).toHaveBeenCalledTimes(3);
|
|
63
|
-
expect(random.mock.
|
|
63
|
+
expect(random.mock.calls).toEqual([[1], [2], [3]]);
|
|
64
64
|
expect(random.mock.results[0]).toEqual({ type: "return", value: a });
|
|
65
65
|
});
|
|
66
66
|
```
|
package/docs/test/mocks.mdx
CHANGED
|
@@ -428,26 +428,26 @@ test("foo, bar, baz", () => {
|
|
|
428
428
|
const barSpy = spyOn(barModule, "bar");
|
|
429
429
|
const bazSpy = spyOn(bazModule, "baz");
|
|
430
430
|
|
|
431
|
-
// Original
|
|
432
|
-
expect(
|
|
433
|
-
expect(
|
|
434
|
-
expect(
|
|
431
|
+
// Original implementations still work
|
|
432
|
+
expect(fooModule.foo()).toBe("foo");
|
|
433
|
+
expect(barModule.bar()).toBe("bar");
|
|
434
|
+
expect(bazModule.baz()).toBe("baz");
|
|
435
435
|
|
|
436
436
|
// Mock implementations
|
|
437
437
|
fooSpy.mockImplementation(() => 42);
|
|
438
438
|
barSpy.mockImplementation(() => 43);
|
|
439
439
|
bazSpy.mockImplementation(() => 44);
|
|
440
440
|
|
|
441
|
-
expect(
|
|
442
|
-
expect(
|
|
443
|
-
expect(
|
|
441
|
+
expect(fooModule.foo()).toBe(42);
|
|
442
|
+
expect(barModule.bar()).toBe(43);
|
|
443
|
+
expect(bazModule.baz()).toBe(44);
|
|
444
444
|
|
|
445
445
|
// Restore all
|
|
446
446
|
mock.restore();
|
|
447
447
|
|
|
448
|
-
expect(
|
|
449
|
-
expect(
|
|
450
|
-
expect(
|
|
448
|
+
expect(fooModule.foo()).toBe("foo");
|
|
449
|
+
expect(barModule.bar()).toBe("bar");
|
|
450
|
+
expect(bazModule.baz()).toBe("baz");
|
|
451
451
|
});
|
|
452
452
|
```
|
|
453
453
|
|
|
@@ -455,10 +455,10 @@ Using `mock.restore()` can reduce the amount of code in your tests by adding it
|
|
|
455
455
|
|
|
456
456
|
## Vitest Compatibility
|
|
457
457
|
|
|
458
|
-
For added compatibility with tests written for Vitest, Bun provides the `vi`
|
|
458
|
+
For added compatibility with tests written for Vitest, Bun provides the `vi` object as an alias for parts of the Jest mocking API:
|
|
459
459
|
|
|
460
460
|
```ts title="test.ts" icon="/icons/typescript.svg"
|
|
461
|
-
import { test, expect } from "bun:test";
|
|
461
|
+
import { test, expect, vi } from "bun:test";
|
|
462
462
|
|
|
463
463
|
// Using the 'vi' alias similar to Vitest
|
|
464
464
|
test("vitest compatibility", () => {
|
package/package.json
CHANGED