Hi! Thanks again for miniflare and this repo π
I'm unable to use jest mocks, at present (unrelated to #2 - I can import { jest } from '@jest/globals'
fine π ).
When I add mock, or spy on a function, I get the error:
/**
β should spy on buildResponse
expect(received).toHaveBeenCalledTimes(expected)
Matcher error: received value must be a mock or spy function
Received has type: function
Received has value: [Function buildResponse]
17 |
18 | test("should spy on buildResponse", async () => {
> 19 | expect(buildResponse).toHaveBeenCalledTimes(0);
| ^
20 |
21 | const res = buildResponse("not found", 404);
22 | expect(res.status).toBe(404);
at ensureMockOrSpy (node_modules/expect/build/spyMatchers.js:1294:11)
at Object.<anonymous> (test/response.spec.ts:19:25)
*/
I've got a repro for you here: https://github.com/ptim/miniflare-typescript-esbuild-jest/blob/repro%2Fjest--received-value-must-be-a-mock-or-spy-function/test/response.spec.ts#L23
It is:
- based off master HEAD: fbf3fcb
- running under node 17
- running tests in the terminal, no vs-code extension trickery
I updated deps, confirmed that tests pass, then added the failing case, then updated to miniflare rc4, but the issue persistsβ¦
Cross referencing related miniflare release notes:
Switched back to CommonJS exports. A primary goal of Miniflare is to provide a fun developer experience. Currently, this is not the case when using Miniflare with a certain popular testing framework (cough, Jest, cough), because it and its ecosystem's support for ESM isn't great yet. This also makes it easier to upgrade from Miniflare 1. Node lets you import CommonJS modules in ES modules so this won't break existing code. Thanks @Kikobeats.
https://github.com/cloudflare/miniflare/releases/tag/v2.0.0-rc.4
AFAICT, this is related to jest vs ESM / esbuild config / ts-jest config, as the project continues to work beautifully in miniflare.
If I come up with anything, I'll report back π Thanks!