Closed jedwards1211 closed 3 months ago
Oh. Looking through the code, it seems like v4 just passes a showDiff
flag to AssertionError
, and I guess Mocha is what does the actual diffing?
Yep, I had to monkey-patch require('mocha/lib/utils').canonicalize
.
I've had two pain points with Chai assertions in projects that use Sequelize:
expect(sequelizeModelInstance)...
fails, the process printsunable to find module 'pg-native'
and crashes before it can format the error diffexpect(somethingContainingASequelizeTransaction)...
fails, the process runs OOM while trying to format the error diffNote: the default
truncateThreshold
isn't preventing this. I am on Chai 4, and maybe Chai 5 somehow avoids these problems, but I'm unable to try Chai 5 yet since it's pure ESM.It would be nice to systematically solve this problem once and for all. There are several ways I could work around this:
expect
with a helper functionexpect
that deeply preprocesses the actual values automaticallyI don't really like any of these options; the latter two don't systematically eliminate the problem, because we would have to patch every existing test file (unless we rewire
chai
imports, I guess) and avoid naively usingexpect
in new tests going forward. And also, modifying the input value could alter the assertion result -- I really just wish I could hook Chai itself to do this preprocessing between when the assertion fails and when it creates diffs.I don't see any kind of option to do this in the docs; do you agree it would be a helpful feature?