Exercise 14.6 problems

In the solutions to exercise 14.6 it introduces const assert = require(‘assert’) in the spec file, and uses it on part c: assert.strictEqual(output, “2 is less than 5.”). This is the first time I am seeing this and don’t recall it in the chapter about Unit testing. Also the 14.6.2 repl.it gives a 404 page not found error.

Hey there,

I had similar issues. Firstly I was able to find the rock, paper, scissors repl at https://repl.it/@launchcode/UnitTestingExercises03

Secondly, it looks like ‘assert’ is another module with assertion functions to assist with testing expected outputs with actual outputs. You can find out more about assert and asser.strictEqual() here..

I didn’t use assert in my exercise, but from what I can see it’s doing pretty much the same thing we have been doing with Jasmine’s expect(myFunction(arg1, arg2)).toEqual(myExpectedOutput).

Hope that helps!

14.6. Exercises: Unit Testing - @jwrounds thanks for assert link - my quick review says we can’t use assert and strict equality here
Did anyone get this to work using the solution two require stmts and assert code?
const test = require(’…/checkFive.js’);
const assert = require(‘assert’);
assert.strictEqual(output, “2 is less than 5.”);
When I try solution code- it throws: Failures: 1) checkFive should return ‘num is less than 5’ when num < 5. Message: ReferenceError: checkFive is not defined let output = checkFive(2); line
This works… when - in spec file - I use:
one require stmt: const checkFive = require(’…/checkFive.js’);
and expect stmt: expect(output).toEqual(“2 is less than 5.”);
I can get Exercise to work properly when I follow what we learned in text reading and exercise instructions; don’t know where assert came from in solution?

Hi @Ebbie,

You should be able to use assert functions be requiring module as you have with require(‘assert’).

When you call assert.strictEqual(output, “2 is less than 5.”) have you defined output as ‘checkFive(2)’? If so, the problem may be that your reference to checkFive.js is defined above as “const test = require(”…/checkFive.js")", thus leaving the phrase “checkFive()” undefined in your .spec file.

Hope that helps!

Thanks much @jwrounds - I can get working both ways now - expect and assert - I like and now understand expect failure messages better because I am used to them with GitHub Autograder!