Skip to content
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

strict mode: use allowUnionTypes to allow union type keyword at "#/properties/image" (strictTypes) during Jest tests #3984

Closed
2 tasks done
112RG opened this issue Jun 9, 2022 · 2 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@112RG
Copy link
Contributor

112RG commented Jun 9, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

npx jest __tests__/get.test.js -t "GET Index"
  console.warn
    strict mode: use allowUnionTypes to allow union type keyword at "#/properties/image" (strictTypes)

      at checkStrictMode (node_modules/@fastify/ajv-compiler/node_modules/ajv/lib/compile/util.ts:212:18)
      at strictTypesError (node_modules/@fastify/ajv-compiler/node_modules/ajv/lib/compile/validate/index.ts:322:18)
      at checkMultipleTypes (node_modules/@fastify/ajv-compiler/node_modules/ajv/lib/compile/validate/index.ts:294:5)
      at checkStrictTypes (node_modules/@fastify/ajv-compiler/node_modules/ajv/lib/compile/validate/index.ts:274:33)
      at schemaKeywords (node_modules/@fastify/ajv-compiler/node_modules/ajv/lib/compile/validate/index.ts:231:18)
      at typeAndKeywords (node_modules/@fastify/ajv-compiler/node_modules/ajv/lib/compile/validate/index.ts:161:3)
      at subSchemaObjCode (node_modules/@fastify/ajv-compiler/node_modules/ajv/lib/compile/validate/index.ts:147:3)

 PASS  __tests__/get.test.js
  GET Pages
    ✓ GET index (84 ms)

route
After upgrading to Fastify@V4 I have started to encounter this warning during the running of my Jest test. Now I know I should be using tap, I just haven't had to to migrate over to it yet. To my knowledge this warning only shows during test and I am guessing this is happening because of the upgrade to Ajv v8 but I am unsure reading there migration guide how to fix this.

This is the route that is being hit

  fastify.get('/', async (req, reply) => {
    return reply.view('login', { captcha: process.env.CAPTCHA_LOGIN, sitekey: process.env.CAPTCHA_SITE_KEY, token: await reply.generateCsrf() })
  })
@mcollina
Copy link
Member

mcollina commented Jun 9, 2022

Fixing this is documented in https://ajv.js.org/strict-mode.html#strict-types. You'd need to use anyOf for one of your schemas.

Would you like to send a PR to https://github.com/fastify/fastify/blob/main/docs/Migration-Guide-V4.md? Thx

@mcollina mcollina added good first issue Good for newcomers documentation Improvements or additions to documentation labels Jun 9, 2022
mcollina pushed a commit that referenced this issue Jun 9, 2022
Add info on migrating to Aja's strict schema
@Eomm
Copy link
Member

Eomm commented Jun 12, 2022

Fixed in #3986

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants
@mcollina @Eomm @112RG and others