timoxley / functional-javascript-workshop

A functional javascript workshop. No libraries required (i.e. no underscore), just ES5.
2.05k stars 438 forks source link

Exercise 8: Basic Call: run/verify throws error, if anything but a number is returned #139

Open eppfel opened 8 years ago

eppfel commented 8 years ago

When testing my faulty solution, run and verify throw Error: [sprintf] expecting number but found undefined "undefined". This happens, if your module returns anything, but a number, e.g.:

function duckCount() {
  return 
}

module.exports = duckCount

Tested {}, [],'' as well.

I was confused first, because the error is thrown inside the workshop script. I think it would be helpful, if a type check was performed to anticipate an error like this. Maybe this is related to other exercises as well.

The full stack:

/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:163
                    throw new Error(sprintf('[sprintf] expecting number but found %s "' + arg + '"', get_type(arg)));
                    ^

Error: [sprintf] expecting number but found undefined "undefined"
    at str_format.format (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:163:12)
    at str_format (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:77:28)
    at Object.vsprintf (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/sprintf/lib/sprintf.js:244:17)
    at Object.defaultTranslation [as translate] (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/i18n-core/index.js:38:15)
    at Object.__ (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/i18n-core/lib/createTranslator.js:34:15)
    at /usr/local/lib/node_modules/functional-javascript-workshop/exercises/basic_call/exercise.js:56:19
    at obtainResult (/usr/local/lib/node_modules/functional-javascript-workshop/exercises/runner.js:100:21)
    at Exercise.<anonymous> (/usr/local/lib/node_modules/functional-javascript-workshop/exercises/runner.js:66:27)
    at next (/usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/exercise.js:182:19)
    at /usr/local/lib/node_modules/functional-javascript-workshop/node_modules/workshopper-exercise/exercise.js:189:7
jhecking commented 8 years ago

I ran into this issue as well in exercise 12 (Function Spies). In the solution, the spy object is expected to have a numeric count property. I had accidentally named the property counter instead in my solution. When verifying my solution I got the same error which was a bit confusing.