Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test client-side code with NodeUnit

This is a follow-up to my previous question.

Suppose I am writing the calculate.js source file with a calculate function to use it in my client-side code:

function calculate(num) {
    return num * 2;
}

Now I would like to test it.

I am using nodeunit as described in this article and export the calculate function (so that tests can invoke it).

function calculate(num) {
    return num * 2;
}

exports.calculate = calculate // Node.js stuff. It won't run in a browser!

The nodeunit tests run OK, but I cannot use calculate.js in my web application any longer since it uses exports.

Now it looks like a catch. Can I fix this problem?

like image 852
Michael Avatar asked Jan 16 '23 07:01

Michael


1 Answers

Use a non-Node.js testing framework like jasminebdd or jstestdriver.

like image 115
ssmithstone Avatar answered Jan 18 '23 22:01

ssmithstone