You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TLDR: Certain functions in node.js application could benefit from fusspot's parameter validation. This could be used as a sort of react-props for node.js which validates only when running the tests.
A lot of times a simple typo could silently sneak in and cause unexpected behaviour. In the example below, emphasise would remain falsy since foo gets the wrong parameter property.
const foo = ({ abc, xyz, tgif, emphasise }) => {
if (emphasise) {
return chalk.bold('I am emphasised');
}
}
foo({ abc, xyz, tgif, emphasize }); // a simple American to British glitch
Also, if a fellow developer decides to change foo's parameter schema, she/he needs to dig into all the call sites of foo to fix it. These problems aren't anything new and can be carefully fixed with unit testing.
My proposal is that we use fusspot along with unit testing to write less test cases and catch bugs early on. A function could be wrapped around an assertion function (v.assertParams?) and the code would only validate when running tests i.e. NODE_ENV=test else it would simply be a passthrough (for performance reasons).
One of the drawbacks of this approach would be that we would need to write the parameters at two places and keep them in sync. Also, it is a non standard solution and might throw some people off.
The text was updated successfully, but these errors were encountered:
TLDR: Certain functions in node.js application could benefit from fusspot's parameter validation. This could be used as a sort of react-props for node.js which validates only when running the tests.
A lot of times a simple typo could silently sneak in and cause unexpected behaviour. In the example below,
emphasise
would remain falsy sincefoo
gets the wrong parameter property.Also, if a fellow developer decides to change
foo
's parameter schema, she/he needs to dig into all the call sites offoo
to fix it. These problems aren't anything new and can be carefully fixed with unit testing.My proposal is that we use fusspot along with unit testing to write less test cases and catch bugs early on. A function could be wrapped around an assertion function (
v.assertParams
?) and the code would only validate when running tests i.e.NODE_ENV=test
else it would simply be a passthrough (for performance reasons).One of the drawbacks of this approach would be that we would need to write the parameters at two places and keep them in sync. Also, it is a non standard solution and might throw some people off.
The text was updated successfully, but these errors were encountered: