diff options
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | testLib/sharedTestCases.js | 2 |
2 files changed, 7 insertions, 5 deletions
@@ -139,9 +139,6 @@ myModule.__with__({ Limitations ----------- -**Using `const`**<br> -It's not possible to rewire `const` (see [#79](https://github.com/jhnns/rewire/issues/79)). This can probably be solved with [proxies](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Proxy) someday but requires further research. - **Transpilers**<br> Some transpilers, like babel, rename variables in order to emulate certain language features. Rewire will not work in these cases (see [#62](https://github.com/jhnns/rewire/issues/62)). A possible solution might be switching to [babel-plugin-rewire](https://github.com/speedskater/babel-plugin-rewire). @@ -182,10 +179,15 @@ Please be aware that you can't rewire `eval()` or the global object itself. API --- -### rewire(filename: String): rewiredModule +### rewire(filename: String, [options]): rewiredModule Returns a rewired version of the module found at `filename`. Use `rewire()` exactly like `require()`. +#### Options +| Property | Default | Description | +|----------|---------|-------------| +| convertConst | false | Set to true to convert all `const` variables of the required module to `let`. This way you can mock const variables. **Caution**: Setting this to true can lead to inaccurate tests. + ### rewiredModule.__set__(name: String, value: *): Function Sets the internal variable `name` to the given `value`. Returns a function which can be called to revert the change. diff --git a/testLib/sharedTestCases.js b/testLib/sharedTestCases.js index ec5e116..ddb8b04 100644 --- a/testLib/sharedTestCases.js +++ b/testLib/sharedTestCases.js @@ -417,6 +417,6 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv + it("Should have correct __filename and __dirname when mocked using convertConst", function() { expect(rewire("./ES2015Module", { convertConst: true }).filename).to.equal(require("./ES2015Module").filename); expect(rewire("./ES2015Module", { convertConst: true }).dirname).to.equal(require("./ES2015Module").dirname); - }) + }); }); |