TestComplete javascript implementation of an Dictionary object bugged.
The code example they give for the new "getActiveXObject("Scripting.Dictionary")" implementation of a dictionary is as follows:
function DictionaryDemo() { let d = getActiveXObject("Scripting.Dictionary"); // Add keys and items. d.Add("a", "Alphabet"); d.Add("b", "Book"); d.Add("c", "Coffee"); // Get the item by key. var s = d.Item("c"); Log.Message(s); // Assign a new item to the same key. d.Item("c") = "Cookie"; s = d.Item("c"); Log.Message(s); // Assign a new key to the same item. d.Key("c") = "Co"; // Remove second pair. d.Remove("b"); if (d.Exists("b")) Log.Message("The pair exists.") else Log.Message("The pair does not exist.") }
This code breaks in a couple of places.
The line 'd.Item("c") = "Cookie";' gives the following error:
JavaScript runtime error.
ReferenceError: Invalid left-hand side in assignment.
The line 'd.Key("c") = "Co";' gives the following error:
JavaScript runtime error.
Error: Member not found.
That's because that's the JScript version of the code. If you go to https://support.smartbear.com/testcomplete/docs/scripting/dictionary-object.html?q=SCripting%20Dictionary and look at the code examples, there are JavaScript, JScript, Python, etc... if you go to the actual JavaScript tab, this is the code that they give. Notice the bolded lines that are different.
function DictionaryDemo() { let d = getActiveXObject("Scripting.Dictionary"); // Add keys and items. d.Add("a", "Alphabet"); d.Add("b", "Book"); d.Add("c", "Coffee"); // Get the item by key. let s = d.Item("c"); Log.Message(s); // Assign a new item to the same key. d.$set("Item", "c", "Cookie"); s = d.Item("c"); Log.Message(s); // Assign a new key to the same item. d.$set("Key", "c", "Co"); // Remove second pair. d.Remove("b"); if (d.Exists("b")) Log.Message("The pair exists.") else Log.Message("The pair does not exist.") }