tape-testing / tape

tap-producing test harness for node and browsers
MIT License
5.77k stars 307 forks source link

How to have greaterthan() or lessthan() assertions in Tap #549

Closed vipulgupta2048 closed 3 years ago

vipulgupta2048 commented 3 years ago

I am bit new to this process as I am migrating some tests back to Tap. I couldn't help but notice there aren't specific assertions for the following to compare numbers. How can I write a similar test for them in Tap. I thought of using t.ok where I can formulate the expression into truthy value for my test but that didn't work out well. I feel I can add some more examples regarding comparisons other than just equal values.

.toBeGreaterThan(number | bigint)
.toBeGreaterThanOrEqual(number | bigint)
.toBeLessThan(number | bigint)
.toBeLessThanOrEqual(number | bigint)

Reference

vipulgupta2048 commented 3 years ago

This could be an ideal solution - t.ok(inputValue >= outputValue, Values are correct.. Test passed)

Raynos commented 3 years ago

I use

t.ok(counter >= 5, `expected ${counter} >= 5`)

I put the value in the message because t.ok() just shows truthy / falsey.

ljharb commented 3 years ago

Back to tap? This is the repo for tape.

vipulgupta2048 commented 3 years ago

My bad,