power-assert icon indicating copy to clipboard operation
power-assert copied to clipboard

assert return value

Open OoDeLally opened this issue 7 years ago • 2 comments

Would it be possible to powerAssert the return value? something like

const functionWhichShouldReturnNumber = (x) => {
  assertReturn(Number.isNumber)
  ...
  return 'bad return type'
}

OoDeLally avatar Nov 24 '17 11:11 OoDeLally

@OoDeLally Thank you for your question!

Short answer: not possible now.

Ensuring postconditions in terms of assertion programming is nice and what I'm interested in.

However, it's not a target of power-assert project. It causes scope creep.

When an idea has come I'll create another tool to enforce postconditions then use it in combination with power-assert. I'm very very interested in creating it.

Thanks and please feel free to ask any questions!

twada avatar Nov 25 '17 12:11 twada

It seems sensible to me to add it to powerassert, as it will share most of its code with powerassert. Since powerassert is already transpiled, how hard would it be to add an assertion check before every return within covered functions? Thanks!

OoDeLally avatar Nov 27 '17 16:11 OoDeLally