Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@std/expect unify internals with @std/testing/mock #6289

Open
anion155 opened this issue Dec 22, 2024 · 0 comments
Open

@std/expect unify internals with @std/testing/mock #6289

anion155 opened this issue Dec 22, 2024 · 0 comments
Labels
suggestion a suggestion yet to be agreed

Comments

@anion155
Copy link

anion155 commented Dec 22, 2024

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 AssertError class
  • toBe/toBeDefined/toBeUndefined/toBeNull uses assertNotStrictEquals and assertStrictEquals
  • toBeInstanceOf uses assertInstanceOf and assertNotInstanceOf
  • 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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion a suggestion yet to be agreed
Projects
None yet
Development

No branches or pull requests

2 participants