Closed damassi closed 9 years ago
Ok, so more progress on understanding this as it applies to testing:
Since upgrading Webpack, I'm now required to "require" rewire
inside of my tests directly. Meaning this:
var rewire = require('rewire');
describe('Test', function() {
it('should work', function() {
var DummyClass = rewire('./DummyClass') // throws error
})
})
But this works:
describe('Test', function() {
it('should work', function() {
var rewire = require('rewire');
var DummyClass = rewire('./DummyClass') // works.
})
});
Another thing: imports
do not work for objects you wish to stub:
// DummyClass.js
import states from 'utils/states';
export default class DummyClass {
constructor() {}
}
// DummyClass-spec.js
describe('Test', function() {
it('should work', function() {
var rewire = require('rewire');
var DummyClass = rewire('./DummyClass');
DummyClass.__set__('states', 'foo'); // throws ReferenceError: states is not defined
})
});
When importing using var states = require('utils/states')
everything is just fine.
Apologies -- lots going on here, but I feel I've been able to narrow the issue down.
Closing this and moving the issue over to focus on imports
That's strange... #12
@jhnns, the setup that they describe in #12 matches mine nearly completely; definitely a duplicate ticket.
Note that I am using the 'rewire-webpack' plugin. Please close if N/A:
I've just finished porting all of my React.js code to ES6 Classes and found that my tests have broken due to Rewire (seemingly) not supporting the new syntax.
Given the simplest example:
And my test, which consists of just a single import:
This error is thrown:
Any assistance would be appreciated!