1

Node has build in assert, https://nodejs.org/api/assert.html

i want to assert the return value is valid, not these cases:

null
undefined
NaN
empty string ("")
0
false

in dev code i can just do

if (value)

but in unit test, what's the assert method ? Again i'm using the native assert from node.js

Thanks !

user3552178
  • 2,719
  • 8
  • 40
  • 67
  • Possible duplicate of [Is there a way to check for both \`null\` and \`undefined\`?](https://stackoverflow.com/questions/28975896/is-there-a-way-to-check-for-both-null-and-undefined) – Jordan Kasper Sep 20 '19 at 15:10
  • not dup, i'm talking about unit test – user3552178 Sep 20 '19 at 15:11
  • It is a duplicate. you simply put that in your assertion. – Jordan Kasper Sep 20 '19 at 15:39
  • sigh, it cannot be a dup. If i put that piece of code in our unit test, it will do the job, but won't pass our code review. Almost all companies require mocha/assert/chai etc frameworks, the code needs to be consistent. – user3552178 Sep 20 '19 at 20:27
  • In that case, you're just asking an opinion-based question? That other question solves the technical problem, if you're just looking for someone to validate what your code reviews demand, then that's just an opinion, and not really a question for StackOverflow. – Jordan Kasper Sep 21 '19 at 15:33

1 Answers1

0

assert.ok(val) ?

would this be the simpliest way ?

user3552178
  • 2,719
  • 8
  • 40
  • 67