deno_std
deno_std copied to clipboard
@std/expect unify internals with @std/testing/mock
Is your feature request related to a problem? Please describe.
For now, there is a misalignment between @std/expect and @std/testing/mock, which causes inability to use @std/expect's fn in @std/testing/mock's assertSpyCalls api, and @std/testing/mock in @std/expect's expect().toHaveBeenCalled() api. Which and prevents us from using both of them at the same time (totally possible for most of the other's apis of both modules).
This seems highly unreasonable, taking into account that both modules uses @std/internal and also @std/expect using @std/assert for some of it's functionalities like:
- same
AssertErrorclass toBe/toBeDefined/toBeUndefined/toBeNullusesassertNotStrictEqualsandassertStrictEqualstoBeInstanceOfusesassertInstanceOfandassertNotInstanceOf- etc.
Describe the solution you'd like
Implement some core mock internals functionality in @std/internal and use it in both modules, agnostic to specifics of @std/assert api and @std/expect jest compatibility, like:
- detection if function is mock function
- gathering of internal calls state
Describe alternatives you've considered
Using compatible between modules storage of mocked function calls, like in @std/expect storing calls in .calls field array, or the other way around in @std/testing/mock storing calls in [Symbol.for("@MOCK")] field
Expected result
Expected result for this would be working code like this:
Deno.test("mock function", async ({ step }) => {
await step("@std/expect should support @std/testing/mock", () => {
const spyFn = spy(() => 5);
spyFn();
expect(spyFn).toHaveBeenCalledTimes(1);
});
await step("@std/testing/mock should support @std/expect/fn", () => {
const mockFn = fn(() => 5);
mockFn();
assertSpyCalls(mockFn, 1);
});
});
PS
I'm willing to start working on this issue my self in my free time, if that's ok
PS
And my other issue about @std/expect's fn not being 'Jest compatible'