DEV Community

Cover image for Meet the New CYPRESS-SCHEMA-VALIDATOR: When ZOD Joined Forces with AJV for the Ultimate Validation Duo!
Sebastian Clavijo Suero
Sebastian Clavijo Suero

Posted on

Meet the New CYPRESS-SCHEMA-VALIDATOR: When ZOD Joined Forces with AJV for the Ultimate Validation Duo!

ACT 1: EXPOSITION

 

I am thrilled to introduce the new CYPRESS-SCHEMA-VALIDATOR plugin, the ultimate successor to CYPRESS-AJV-SCHEMA-VALIDATOR! Combining all the power of AJV schema validation from its predecessor and now also featuring ZOD Schema Validation, and new features. 🔥 🔥 🔥

The CYPRESS-SCHEMA-VALIDATOR is fully backward-compatible with the previous version, and continues to integrate smoothly with leading Cypress API plugins like @bahmutov/cy-api and cypress-plugin-api.

This new version represents a significant leap forward in flexibility, usability, and debugging efficiency.

Image description


ACT 2: CONFRONTATION

 

🤔 What’s New?

  • Support for Both AJV and ZOD Validators: Choose between AJV and ZOD for schema validation, offering versatility for diverse workflows.

Image description

  • Terminal Display of Schema Errors: Schema errors are now shown directly in the terminal during run mode, simplifying debugging.

Image description
 

  • Customizable Styles: Add a personalized touch by using custom icons and HEX colors to better distinguish validation issues.

Image description
 

  • Consistent Error Format: Enjoy unified error formatting, regardless of the validator selected (AJV or ZOD), for seamless and clear reporting during testing.

Image description

 

⏮️ Fully Backward Compatible?

 

AFFIRMATIVE! 🤟🤟🤟

 

🛸 How Do I Migrate?

Upgrading your Cypress framework from CYPRESS-AJV-SCHEMA-VALIDATOR to the new CYPRESS-SCHEMA-VALIDATOR is as simple as this:

1) Uninstall the previous plugin:

npm uninstall cypress-ajv-schema-validator
Enter fullscreen mode Exit fullscreen mode

2) Install the new plugin:

npm install -D cypress-schema-validator
Enter fullscreen mode Exit fullscreen mode

3) Replace previous imports in your project:

Replace:

import 'cypress-ajv-schema-validator'
Enter fullscreen mode Exit fullscreen mode

With:

import 'cypress-schema-validator'
Enter fullscreen mode Exit fullscreen mode

 

✔️ What About the existing .validateSchema() Command In My Code?

No worries, you don’t need to refactor your test cases beyond the imports!

  • The .validateSchema() command still works with AJV schemas.

  • A new alias, .validateSchemaAjv(), is also available for AJV validation.

  • Additionally, the plugin introduces .validateSchemaZod() for ZOD schema validation.

That's it, NO DRAMA-LAMA! 🦙🦙🦙

If you're looking for drama, check out my article series: The Test Drama: Cypress and Playwright, Who Steals the Show? 😁


ACT3: RESOLUTION

 

Don't wait! Upgrade your Cypress framework with the new CYPRESS-SCHEMA-VALIDATOR and enjoy unparalleled flexibility for schema validations using two of the most powerful validators available today: AJV and ZOD (plus many other perks).

You can find it in:


I'd love to hear from you! Please don't forget to follow me, leave a comment, or a reaction if you found this article useful or insightful. ❤️ 🦄 🤯 🙌 🔥

You can also connect with me on my new YouTube channel: https://www.youtube.com/@SebastianClavijoSuero

If you'd like to support my work, consider buying me a coffee or contributing to a training session, so I can keep learning and sharing cool stuff with all of you.
Thank you for your support!
Buy Me A Coffee

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more