Search code examples
javascriptecmascript-6async-awaitecmascript-2017testcafe

Calling super class' async method from async method in extending class


I'm writing JavaScript (> ECMAScript 6) and I can't figure how to call a super class' async method in an extending class' method. This is what I'm trying to do:

class SuperClass {
    constructor(){}

    async method() {
        return;
    }
}

class ExtendClass extends SuperClass {
    constructor() {
        super();
    }

    async method() {
        return super.method();
    }
}

The above won't compile, getting this as error:

SyntaxError: 'super' keyword unexpected here
    at Object.<anonymous> (Path/To/File.js:line:character)

Am I actually trying to do something that isn't possible? Can't seem to Google anything useful..

It does not help to await the call to the super class, it does not help to have different method names - the only thing that helps is making the extending class' method non-async.


Solution

  • This is due to the transpilation used in the testing framework, TestCafe (as stated by @Bergi). I will direct the question elsewhere. Thanks for the comments.

    UPDATE

    This is currently a bug in the TestCafe framework (link to bug). The workaround is as follows:

    async method () {
        return await SuperClass.prototype.method.call(this)
    }