I am trying to test an ES6 class method that calls the class method in its parent. For instance:
Polygon.js
class Polygon { verifyDimensions() { this.allSidesValid(); } } export default Polygon;
Square.js
import Polygon from './Polygon'; class Square extends Polygon { verifyDimensions() { super.verifyDimensions(); if( this.height !== this.width ) { throw new Error( 'Not square' ); } } }
I want to check Square proofDimensions without causing polygon checking. Testing with sinon / chai seems like babeljs creates a copy of the original method when creating the class. It is very difficult to drown.
For example, if I configured my test as follows:
Square.spec.js
beforeEach( () => { sinon.stub( Polygon.prototype, 'verifyDimensions' ); context.verifyDimensions = Square.prototype.verifyDimensions; } );
super.verifyDimensions() still refers to Polygon.prototype.verifyDimensions and will be a test error.
source share