-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Joi.attempt(config, Schema.schwifty) validation fails in Jest tests #68
Comments
Curious! Is jest configured to use any sort of transpilation (e.g. via babel)? |
Ah, why didn't I think about it! Indeed it is:
But without it I get the |
Yep, seems like it's mutually exclusive. I've tried to replace babel polyfill with regenerator-runtime:
and got the same Joi validation error as described in the first post. Can maybe the Joi schema be made less restrictive?
|
There's really no need to transpile classes away in nodejs, and I highly suggest testing the code you're going to run in production, which I hope is not transpiled for a variety of reasons. I think the fix here is to your project's test suite. Mostly likely the polyfill itself is not responsible for the transpilation of classes to functions—you likely have @babel/preset-env setup somewhere, and you can try to configure that to omit certain transformations, or to only transpile your client-side directories. |
I was wrong, sorry for bothering you. :) For anyone facing the same problem: indeed, the solution is just to exclude the server (but not the client) code from being transpiled altogether:
See details here: https://jestjs.io/docs/en/configuration#transformignorepatterns-array-string |
Glad you got it sorted out! |
I'm getting a Joi validation error on configuration object inside the
internals.schwifty
when trying to create a server inside Jest tests. Everywhere else (includingNODE_ENV=test npm start
) the server is being created just fine. The error disappears if I don't export any models.Details and steps to reproduce:
In any Jest test file:
the command
npm run test:jest -- example.test.js
fails with the following:but if I transform the test file into a plain JS script:
and run it with
NODE_ENV=test node example.js
everything works fine and I see the server object being printed to stdout without any errors.The error also disappears if I export an empty array for models:
I'm using Schwifty 4.2.0
The text was updated successfully, but these errors were encountered: