-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
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
TypeError: Class constructor Alg1 cannot be invoked without 'new' #119
Comments
Could you give the exact error? |
|
I cannot reproduce this error. Would you be willing to give some example code where you experience this error? You're node version could also help :) |
Node: 8.9.1 |
Here is the most trivial example. Three files in the same folder. class Alg1 {}
module.exports = Alg1;
const Alg1 = require('./alg1');
class Alg2 extends Alg1 {}
module.exports = Alg2;
const rewire = require('rewire');
const Alg = rewire('./alg2');
let a = new Alg(); Run
|
@JvJefke - did the example help to reproduce? It's 3 files, total 8 lines of code, and it's 100% reproducible for me. Please, have a look |
Thanks for the example! |
I still can't reproduce this error. I added a test with your example, but it doesn't fail in node 8.9.1 on my computer. see: JvJefke@35d4398 |
Hmm, weird. I wonder - do you babelize your tests? What happens if you just run the test (or just a code that rewire-s and instantiates, like my 3rd file) from command line using plain node? |
I also ran it from command line using plain node and it still worked. Rewire uses babel internally to convert constants (const) to variables (var), but the tests itself aren't babelized. Could you perhaps pull the |
Pulled the branch and |
Oh, found what is causing it: I have a Please, let me know if there is anything I can do to help resolving this... {
"presets": ["es2015"],
"plugins": ["transform-class-properties"]
} |
I opened a PR to fix this: #123. |
My pleasure! Thanks guys for keeping this tool being one of top unit-testing utilities. |
I have two classes:
Alg1 extends Alg2
.When I
rewire
Alg2 and call its constructornew Alg2()
,I get the error in the title.Only fails on
3.0.0
. Downgrading to 2.5.2 for now - all works fine there.The text was updated successfully, but these errors were encountered: