tannerntannern / ts-mixer

A small TypeScript library that provides tolerable Mixin functionality.
MIT License
379 stars 27 forks source link

Getting an error when using with Jest #39

Closed Code-Quake closed 3 years ago

Code-Quake commented 3 years ago

When I try to run a test on a class I've applied a mixin to I get this error: TypeError: Cannot redefine property: Symbol(Symbol.hasInstance) at Function.defineProperties ()

Any thoughts on how I can get around this?

tannerntannern commented 3 years ago

Hi @CobaltCoder, I believe some others have mentioned having issues with Jest, but I have not confirmed whether Jest is the actual culprit. If you could create minimal reproducible example repo, I'd be happy to look into it more.

S0c5 commented 3 years ago

I'm facing the same issue, I traced the error to copyProps in utils.ts, it happens when a non configurable props is tried to set into the dest, a work-around is:

export const copyProps = (dest: object, src: object, exclude: string[] = []) => {
    const props = Object.getOwnPropertyDescriptors(src);
    for (let prop of exclude) delete props[prop];
+   for (let propName in props) props[propName].configurable = true;
    Object.defineProperties(dest, props);
};

I'm preparing a PR for this issue.