should handle toString -The toString method should return the correct hierarchy (no reply)

前端 未结 2 1423
盖世英雄少女心
盖世英雄少女心 2021-01-26 18:07

I\'m working on a test and a lot of unit(hidden) tests were given , however I ran into this error with a block of my code. Can you all please help me out?

getStr         


        
2条回答
  •  庸人自扰
    2021-01-26 19:00

    Try this... it worked for me

     getString(comment) {
        const authorName = comment.getAuthor().getName();
        if (!comment.getRepliedTo()) return authorName;
        return `${comment.getMessage()} by ${authorName} (replied to ${this.getString(comment.getRepliedTo())})`;
      }
      toString() {
       if(!this._repliedTo){
          return `${this._message} by ${this._author.getName()}`;
        } else {
          return `${this._message} by ${this._author.getName()} (replied to ${this._repliedTo.getAuthor().getName()})`
        }
      }
    

提交回复
热议问题