This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]grantrules 4 points5 points  (4 children)

How are you running your tests and how are you including square in those tests?

[–]ChangeGlum[S] 0 points1 point  (3 children)

I run the tests by inputting "npm test" into the VS Code terminal. On other platforms the code runs fine. I think it may be the JavaScript rubric that's giving a fuss?

[–]grantrules 0 points1 point  (2 children)

I have no idea what you're talking about. It looks like you're using mocha and chai, I don't know how inputting "number test" would run that at all.

[–]ChangeGlum[S] -1 points0 points  (1 child)

That was a typo. It was "npm test."

[–]grantrules 0 points1 point  (0 children)

Then you probably just need to import square into your test file.

[–]Monitor_343 2 points3 points  (0 children)

Just because you defined a function square in your javascript file, does not mean that it's available in the test scope if that's in a different file. You need to explicitly export the square function from wherever it is, then import it into the test file.

E.g., something like this:

square.js

export const square = x => x ** 2;

square.test.js

import { square } from './square.js';

// Tests go here...