Forum Discussion

francisd84's avatar
francisd84
Contributor
4 years ago
Solved

Javascript template litterals don't seems to work

According to documentation, JavaScript language in TC is supporting the template litterals to format strings

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/format.html

 

But even the example shown in the documentation doesn't seems to work.

 

To ensure that I was not in JScript, I created a new project with JavaScript language selected.

 

Then, I created a script function with:

var str = "test";

Log.Message("This is a ${str}");

 

The output is:  This is a ${str}

 

TC version: 14.40.1658

Someone can confirm?

 

Thanks!

  • Nevermind... I found the problem: need to replace " by ` for litterals to be taken into account.

     

    So: Log.Message(`This is a ${str}`) is working.

     

    Thanks a lot!

2 Replies

  • BenoitB's avatar
    BenoitB
    Community Hero

    On my TC it works well :

     

    function test() {
      const htmlTag = String.raw`test`;
      Log.Message(`${htmlTag}`);
      const htmlTag2 = `test2`;
      Log.Message(`${htmlTag2}`);
      var htmlTag3 = `test3`;
      Log.Message(`${htmlTag3}`);
    }
    • francisd84's avatar
      francisd84
      Contributor

      Nevermind... I found the problem: need to replace " by ` for litterals to be taken into account.

       

      So: Log.Message(`This is a ${str}`) is working.

       

      Thanks a lot!