I have this odd situation in unit tests when I have to check function that does return value which can't be made manually (value). In fact this function is made for creating this value. So test like this (javascript and QUnit framework):
asyncTest("UTF-8 - ArrayBuffer conversion", 1, function() {
var arrayBuffer;
var testUtf8 = "łużyński";
var blob = new Blob([testUtf8]);
var f = new FileReader();
f.onload = function(e) {
arrayBuffer = e.target.result;
start();
};
equal(utf8ToArrayBuffer(testUtf8), arrayBuffer, "UTF-8 to ArrayBuffer, OK!");
});
Is redunant, because preparing arrayBuffer variable to compare it with returned value is actually the same as using utf8ToArrayBuffer(testUtf8)
, so test would look like this:
equal(utf8ToArrayBuffer(testUtf8), utf8ToArrayBuffer(testUtf8), "UTF-8 to ArrayBuffer, OK!");
Should I test things like this or leave it? Or maybe there is another approach to this?