We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
My goal is to unit test the following Node.js script (heavily simplified for readability):
script.js
//setup console.log("dosomething"); callfunction(); //functions function callfunction(){ return "function called"; }
with the following mocha / chai test:
/test/test_script.js let assert = require("assert"); describe("script", () => { it("should equal function called", () => { assert(callfunction() === "function called"); }) })
This obviously doesn't work as callfunction() is not recognized. So i tried using the module "rewire" to obtain the function:
let assert = require("assert"); let rewire = require("rewire"); //tonguetwister right there let path = require("path"); describe("script", () => { it("should equal function called", () => { let app = rewire(path.resolve("script.js")); callfunction = app.__get__("callfunction"); assert(callfunction() === "function called"); }) })
This however, instead of just executing callfunction(), executes the entire script, including the initial console.log("dosomething").
The text was updated successfully, but these errors were encountered:
No branches or pull requests
My goal is to unit test the following Node.js script (heavily simplified for readability):
script.js
with the following mocha / chai test:
This obviously doesn't work as callfunction() is not recognized. So i tried using the module "rewire" to obtain the function:
This however, instead of just executing callfunction(), executes the entire script, including the initial console.log("dosomething").
The text was updated successfully, but these errors were encountered: