HeliosLang/compiler

test-automation expect(...).`.toEqual()` wrong on MintingPolicyHash

Closed this issue · 3 comments

 ❯ tests/StellarContract.test.ts:222:36
    220|                 const t2 = await h.setup({randomSeed: 43});
    221|                 console.log(t2.mph.toBech32(), t.mph.toBech32())
    222|                 expect(t2.mph).not.toEqual(t.mph);

These two MintingPolicyHash objects are different references (toBe() doesn't match them).

Their toBech32()s are clearly different. But not.toEqual() fails.

.eq(other) works. but doesn't integrate with jest / vitest.

I think this may also be the case for some other types - hopefully they can all be fixed without much difficulty.

I think you have to fall back to comparing the result of toString() for many types. According to the jest documentation toEqual compares the enumerable properties of an object, and the #bytes field of a MintingPolicyHash is strictly private and isn't visible from outside.

v0.15.0 exposes the bytes property of MintingPolicyHash (along with several other properties of other classes)

Now Jest should work correctly for these types

Thank you, Christian!