Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

test: introduces custom chai assertions #204

Merged
merged 3 commits into from
Jun 25, 2019

Conversation

artem-zakharchenko
Copy link
Contributor

@artem-zakharchenko artem-zakharchenko commented Jun 21, 2019

These changes introduce custom Chai assertions to use in Gavel unit and integration tests.

Motivation

  • To have less verbose test suites
  • To have common assertions integrated into chai chainable operators. Common assertions include:
    • result/field validity
    • expected/real type
    • errors
  • To get rid of implementation details in test, and centralize validation result references (to rely on validation result structure in a single place–custom assertions declaration)
  • To enhance test exceptions with more information about the scenario (include stringified validation result and optional hints)

GitHub

Roadmap

  • Implement custom assertions
    • result and field validity
    • validator
    • expectedType
    • realType
    • errors / noErrors
  • Use expect instead of assert for better readability of custom assertions
  • Ensured consistency of assertions between test suites
  • Consider using to.not.have.validator as a replacement for .to.have.validator(null)

.eslintrc.js Outdated Show resolved Hide resolved
@artem-zakharchenko
Copy link
Contributor Author

Experienced #139, restarting the build.

Copy link
Contributor

@honzajavorek honzajavorek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except the leftover commented-out code I marked with a dramatic chipmunk it is truly... beautiful!

.eslintrc.js Outdated Show resolved Hide resolved
test/integration/validate.test.js Outdated Show resolved Hide resolved
test/unit/units/validateBody.test.js Outdated Show resolved Hide resolved
@artem-zakharchenko
Copy link
Contributor Author

I still would like to provide errors assertions as a part of this pull request, just to make it clear. Focusing on them now.

@honzajavorek
Copy link
Contributor

I think it is completely okay to merge this now and add them in a separate PR, but up to you.

@artem-zakharchenko
Copy link
Contributor Author

Custom assertions for the errors were also added, so the pull request should be complete!

I ditched an idea to have to.not.have.validator, because I think that conceptually means there is no validator property, which is not the expected behavior.

Copy link
Contributor

@honzajavorek honzajavorek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@artem-zakharchenko artem-zakharchenko merged commit 2eb036d into master Jun 25, 2019
@artem-zakharchenko artem-zakharchenko deleted the 184-chai-assertions branch June 25, 2019 08:22
@ApiaryBot
Copy link
Collaborator

🎉 This PR is included in version 6.1.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider custom chai assertions
3 participants