speedskater / babel-plugin-rewire

A babel plugin adding the ability to rewire module dependencies. This enables to mock modules for testing purposes.
843 stars 90 forks source link

Rewire Parent Class #161

Closed dtothefp closed 7 years ago

dtothefp commented 7 years ago

Doesn't seem possible to do:

import Parent from './some-parent'

export default class Child extends Parent {}

then rewire

import Child from './child'

Child.__Rewire__('Parent', class {
   constructor(arg) {
      //thought this would be invoked but isn't ¯\_(ツ)_/¯
   }
})

const child = new Child()

Am I missing something or is this just not a use case for Rewire?

speedskater commented 7 years ago

@dtothefp Sorry for the late reply. Unfortunately this is not a case for babel-plugin-rewire.

The reason is that Parent is already bound to the imported class when Child is declared. If you want to rewire the superclass you have to export a factory function.