How To Expose External Library In Browser So Jest Unit Tests Can See It?
I'm writing a math library to be used in a browser, and using Jest to run unit tests on it (which I realize is more geared toward Node). I've solved most of the issues by extendin
Solution 1:
The global namespace object in Node
is available as global
.
You can add math
to the global namespace object like this:
global.math = require('./math.js');
const { cv } = require('./CalRunWebMath.js');
test('Calculates coefficient of variation', () => {
var data1 = [10.4, 20.3, 30.2, 40.1];
expect(cv(data1)).toBe(0.5061720808904743); // Success!
});
Post a Comment for "How To Expose External Library In Browser So Jest Unit Tests Can See It?"