How to replace javascript method of super class for testing?

I want to test a method 'foo' that calls its super method 'foo':

foo(){
     super.foo();
     //do some extra stuff
}

If it would reference another method from the same class, e.g.

foo(){
     this.baa();
     //do some extra stuff
}

... i could simply replace the baa method for testing, e.g

element.baa = () => { console.log('This is a mock of baa')};
element.foo();

expect(effectsOfFoo).toBe(Ok).

However, how to replace the super method 'foo'?

Maybe something like

element.constructor.getSuperClass().foo = () => { console.log('This is a mock of super foo')};

However, I did not manage to get the super class, yet.

Related questions:

spying on/mocking super class methods in es6

Answers:

Answer
element.constructor.__proto__.prototype.foo = () => {
                        console.log('This is a mock of super foo');
                    };

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.