dai-shi / proxy-memoize

Intuitive magical memoization library with Proxy and WeakMap

Home Page:http://proxy-memoize.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Jest cannot recognize bundled file

Mingx94 opened this issue · comments

// utils
import memoize from "proxy-memoize";

export const getOptions = memoize((x) => {
  if (!x.Options) {
    return [];
  }

  return x.Options.map((o) => ({
    value: o.Value,
    text: o.Text
  }));
});

// utils.test.js
import { getOptions } from "./utils";

describe("package", () => {
  it("will throw error", () => {
    let options = getOptions({ Options: [{ Value: 1, Text: 2 }] });

    expect(options).toEqual([{ value: 1, text: 2 }]);
  });
});

Jest will show this error

TypeError: (0 , _proxyMemoize.default) is not a function

example codesandbox

Yeah, I found this error when I use it in valtio.
So far, what I found as a workaround is this.

To be honest, I'm still not sure what is blocking because zustand uses default export too and it should be working fine.

I'm searching the solution all day and found nothing.
Thanks for the workaround!

@dai-shi not sure if this helps but I've read that this issue can be caused by circular dependencies. It seems unlikely that there could possibly be circular deps between valtio and this but this came up when I was looking at this problem yesterday: kulshekhar/ts-jest#1873 (comment)

The issue is ES default export handling. But, circular dependencies might be somehow related. Thanks for the link.

So what is the solution?

We don't know how to fix it properly on our end.
A workaround is something like this.

Thanks. Will give it a try