Ask a Question

Javascript String Interpolation

SOLVED
jaward916
Occasional Contributor

Javascript String Interpolation

Is Javascript string interpolation allowed/recognized in TestComplete (14.70 fully patched)?

The reason I ask is when I'm logging some values I much prefer interpolation to concatenation.

i.e. I would like to use:

Log.Message(`Found match, group ${i}: ${m[i]}`);

instead of:

Log.Message("Found match, group " + i + ":" + m[i]);

both are valid JS and work on online prototypers, however the former (interpolation) results in Syntax Errors on the ` (backtick).

Does anyone know if this is a limitation in TestComplete or whether there's a syntax difference I need to be aware of, I couldn't find any documentation for this!

1 ACCEPTED SOLUTION

Accepted Solutions
jaward916
Occasional Contributor

Re: Javascript String Interpolation

Wait a minute...

I did some digging, and it would seem this project is in fact JScript and not JavaScript (which also explains another issue I nearly put on here).

I have just run the Javascript conversion (a great feature) and I can now write as I expect. at least I've only wasted 2 hours πŸ™ƒ

View solution in original post

4 REPLIES 4
Wamboo
Community Hero

Re: Javascript String Interpolation

This works wery well for me:

 

function testInterpolation() {
  var i = "i_value";
  var arr = ["value1", "value2"];
  
  Log.Message(`This string contains that two variables: first one -> ${i} and second one -> ${arr[1]}`);
}

 

I'm using the latest version of TestComplete.

jaward916
Occasional Contributor

Re: Javascript String Interpolation

Thanks, @Wamboo, so I just pasted this straight into my test script, and straight away it has the red x with a syntax error:

jaward916_0-1604324331956.png

 

jaward916
Occasional Contributor

Re: Javascript String Interpolation

Wait a minute...

I did some digging, and it would seem this project is in fact JScript and not JavaScript (which also explains another issue I nearly put on here).

I have just run the Javascript conversion (a great feature) and I can now write as I expect. at least I've only wasted 2 hours πŸ™ƒ

View solution in original post

Wamboo
Community Hero

Re: Javascript String Interpolation

I was just wondering if you have a project in Jscript πŸ™‚ It's great that you managed to fix it.

cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β