Create extended anonymous class for Abstract class in TypeScript

Report
Question

Please briefly explain why you feel this question should be reported .

Report Cancel

I have abstract class which has few implemented protected methods and few abstract methods.
I am trying to write some tests for the protected methods.

Since these are not available even in the extended classes to outside world, I would like to create anonymous Test class which can extend and verify/mock my stuff.

export abstract class AbsClass implements AbsInterface {

    protected extract(filter: string) {
    //some implemented code to test
    }

    abstract someMethod();
}

I am not able to figure out how to create something like this anonymously

export class TestClass extends AbsClass {
   public testExtract(){
        //call super.extract and verify result
   }
}
solved 0
1 Answer 9 views 0

Answer ( 1 )

    1
    December 6, 2016 at 2:04 pm

    Please briefly explain why you feel this answer should be reported .

    Report Cancel

    I’ve run into this before. It seems like the export/abstract keywords interfere with each other. I’ve had to define the class and then export on a separate line to get around this.

    Example:

    abstract class BaseClass {}
    
    export default BaseClass
    
    Best answer

Leave an answer

Browse

What is the capital of Egypt ? ( Cairo )

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>