I'm getting weird results in one of my tests. I'm...
# testing
t
I'm getting weird results in one of my tests. I'm passing a value into a function, it gets processed and wrapped up in some XML, and in this particular case, I'm trying to verify that it came through the processing step unedited. So I have
Copy code
var testValue = '{abc:"def"}';
var actualValue = myComponent.getFormattedText(testValue);

expect(actualValue).toInclude(EncodeForXML(testValue));
And that's "failing" because
The needle [&#x7b;abc&#x3a;&#x22;def&#x22;&#x7d;] was not found in [<?xml version="1.0" encoding="UTF-8"?><record><datum key="id">{abc:"def"}</datum></record>
I think it's worth noting that getFormattedText also runs testValue through EncodeForXML under the hood. So it's especially a mystery to me why it comes out nice on one side, but not on the other. Why is EncodeForXML feeling a need to encode the braces and quotes in one string, but not the other, causing them to not match?
a
You are explicitly calling
EncodeForXML
on the needle. You're not encoding
{abc:"def"}
in the XML, and comparing it to the encoded version. I mean... the test failure is even showing you... exactly... erm... that...
&#x7b;abc&#x3a;&#x22;def&#x22;&#x7d;
clearly isn't the same as
{abc:"def"}
, right?
t
The confusion was because I am encoding
{abc:"def"}
in the XML though... So I couldn't understand why they were encoding differently. If anything, I was expecting
Copy code
<?xml version="1.0" encoding="UTF-8"?><record><datum key="id">&#x7b;abc&#x3a;&#x22;def&#x22;&#x7d;</datum></record>
But I figured it out. The raw XML I'm returning is actually this:
Copy code
<dataset type="null"><record><datum key="id">&#x7b;abc&#x3a;&#x22;def&#x22;&#x7d;</datum></record></dataset>
But then I was parsing out the record tags to get a count of rows returned via
XMLSearch(XMLParse())
(which I had forgotten about) and so the
actualValue
in my test was really an XML object, which it seems TestBox was running
ToString
on, and when CF output the string, it encodes things differently than
EncodeForXML
does.
So my test passes when I use my real output, instead of my XMLParsed output (which was frankly a dumb thing to do anyway)
😜 1