Skip to content

Commit

Permalink
added reproduction test case for jhnns/rewire#181
Browse files Browse the repository at this point in the history
  • Loading branch information
bugy committed Apr 13, 2020
0 parents commit 6f406d3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions another_file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
printGlobalVar: function () {
console.log('someGlobalVar in another_file: ' + someGlobalVar);
}
}
11 changes: 11 additions & 0 deletions case_181.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const printGlobalVar = require('./another_file').printGlobalVar;
require('./my_global');

const MyClassModule = require('rewire')('./my_class');
global.MyClass = MyClassModule.__get__('MyClass')

test('some stub test', () => {
console.log('someGlobalVar in test: ' + someGlobalVar);
new MyClass('Hello world');
printGlobalVar();
});
6 changes: 6 additions & 0 deletions my_class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class MyClass {
constructor(text) {
console.log('someGlobalVar in MyClass: ' + someGlobalVar);
console.log(text + ' created!');
}
}
1 change: 1 addition & 0 deletions my_global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.someGlobalVar = 'abc';
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "rewire_181",
"version": "0.0.1",
"private": true,
"scripts": {
"test": "jest"
},
"dependencies": {},
"devDependencies": {
"jest": "^25.3.0",
"rewire": "^5.0.0"
}
}

0 comments on commit 6f406d3

Please sign in to comment.