Asking
Asking

Reputation: 4192

Next JS using cypress for functions unit testing

I noticed in cypress documentation that we can use Cypress for testing components. But i did not find any info regarding using cypress to test simple javascript functions like:

function isObjectLike(value) {
  return value != null && typeof value == 'object' && !Array.isArray(value);
}

In my situation i am using cypress to test Nextjs application. I test my components with unit tests and also for integration tests. So all my tests are visual tests.
I want also to tests my utlis/helpers functions using unit tests.
Question: Could i do this with cypress or it is not designed for what i want to do?

Upvotes: 0

Views: 891

Answers (1)

tymzap
tymzap

Reputation: 944

Conventionally Cypress was designed to run test in browser environment, and it has tools which helps this purpose. For the most time, for unit testing your functions you'd rather want to use JavaScript test runner like Jest.

However, according to Cypress documentation, there are cases when you would want to do unit tests in this framework: for example if you want to test if some property is present on your window object. See example.

Bottom line: Pure JavaScript test runners have more tools and are probably better for unit testing functions.

Upvotes: 1

Related Questions