Questions tagged [rewire]
21 questions
0
votes
1 answer
How can I test un-exported pre ES6 JS files with karma/jasmine?
I have a plain JS file that is written with pre ES6 JS code that I want to test using a karma/jasmine test suite. The file is large but I just want to get a super simple example working.
// pluginV3.js
// This is the file I am trying to test. It is…

Rosey
- 739
- 1
- 12
- 27
0
votes
1 answer
Module variables not clear between tests in Jest
I would like to be able to isolate the side effects that seem to be related when testing two functions that modify the same state variable myVar independently of each other.
example.js
export function foobar() {
sideEffect1();
…

DraQ
- 340
- 2
- 13
0
votes
1 answer
Unit testing - mocking a config file referenced in a method
I'm trying to test a method that contains a reference to a global variable containing some configs taken from a json file.
async function methodToTest(var1, var2, var3) {
const functionName = 'methodToTest';
//guards here
try…

Eunito
- 416
- 5
- 22
0
votes
1 answer
How do I get everything covered?
I have a node module I'm trying to write unit tests for. Here's a part of the module:
function _write(level, message) {
if (level <= _current) {
message = message || "No message provided.";
const consoleFn =…

Colin
- 331
- 3
- 19
0
votes
1 answer
Mocha unit test on a non exported function returns 'xx is not a function'
I'm trying to run a unit test on a non exported function using mocha, but it gives an error 'xx is not a function'. Sample structure is like the ff code, wherein I'd like to test the function isParamValid. The code format in settings.js already…

jamu
- 3
- 1
0
votes
1 answer
How to mockup a constant defined in another file using sinon and rewire?
I'm a beginner with JS tests and I'm having issues when I try to mockup the value of a constant in the file I need to test.
I have the following file
// index.js
const { MultiAccounts } = require('../../some.js')
const MultiAccountInstance = new…

fingerprints
- 2,751
- 1
- 25
- 45