Forum Discussion

DanMM's avatar
DanMM
New Contributor
27 days ago
Solved

Is there any way to get code completion to function when using classes?

Hi all, I'm working a little with classes inside of TC, and have have been rubbing up against an issue with code completion (intellisense) not working. If I have the two blocks of code in different .js files;

 

class foo  {
  constructor(panel)  {
    this.panel = panel;
  }
}

function LogMessage(){
  Log.Message(`This Is a Logged Message from the parent class`)
}

module.exports = {Foo: Foo}

 

 

const foo = require("Foo");


class Bar extends Foo.Foo{
  
  constructor(panel){
    super(panel);
  }

}

function secondClassFunction(){
  Log.Message(`This is the child class`)
  
}

 

module.exports = {Bar:Bar}

And then in a third .js file, have another code block calling the 'Bar' class like the following

 

var Bar= require("Bar");


function FunctionName(){

  const x = new Bar.Bar(`panel`);  

}

Typing 'x.' won't generate any intellisense prompts to appear. Has anyone seen this before \ is there a solution \ work around? I understand there might be a few different ways to implement inheritance (which is my ultimate goal, since Bar is a child of Foo), so if anyone has any suggestions for rewriting this that might help, the feedback would be appreciated.

Thanks,

Dan

5 Replies

  • Hi, there,

    It looks like the IDE doesn't look more than 2 levels deep in user scripts...

    Be careful with the use of javascripts classes/objects because, even if it works, I've personally encountered many problems when debugging (class fields reset when using a breakpoint) which makes development difficult to maintain.

    I've now backed off except when I couldn't do otherwise.

  • DanMM's avatar
    DanMM
    New Contributor

    Thanks all for the advice here. It seems classes might be a bit difficult to maintain given the state of TestCompletes' editor. I'll look to other solutions for what I'm attempting to achieve.

    • rraghvani's avatar
      rraghvani
      Icon for Champion Level 3 rankChampion Level 3

      There's nothing wrong with using Classes. I use Singleton design pattern class in JavaScript which is instantiated once and used throughout all scripts at the beginning. I used this method to initialise various settings. This script is located in Common Project within the Project Suite, it also includes a number of methods. 

      As the code completion/intelli-sense is not supported, I have to refer to the class constantly!

      If you do decide to implement classes, refer to https://support.smartbear.com/testcomplete/docs/scripting/specifics/javascript.html . I also suggest you to keep it simple.