QUnitGS2
QUnitGS2 copied to clipboard
Testing procedures calling helper functions or other procedures
Hi,
I try to test a quite long procedure onClick
, see below, (I mean here a procedure as understood in JS: returning nothing, just writing calculation results out into a Google sheet) that consists of many other sub-procedures or functions.
Whereas testing a single function (a function as understood in JS: returning something; some of these functions don't take an input) or procedure (some of them take an input) all works fine and according to instructions from: http://qunitgs2.com/.
However tests for that long procedure (using successfully tested single functions/procedures) don't work: after depolying the test code as a web app and clicking latest code
(everything exactly as by previously described code tests) a html tab pops out with a proper header, etc, but no tests run. What is more the test code doesn't call the tested procedure at all. However, it was calling tested single functions/procedures; they run and changed the sheet they worked on. Moreover, they don't need to be included in assert
object.
Does it mean that it's impossible to test such procedures: being a set of other functions or procedures? Or is it something else?
Here the test suit:
let QUnit = QUnitGS2.QUnit;
function doGet() {
QUnitGS2.init();
QUnit.module('Script test');
QUnit.test('onClick function', function(assert) {
//when
onClick(); // At the end it writes a figure in a sheet's G11 cell.
//then
assert.equal(mainSheet.getRange('G11').getValue(), '2.10970231', 'provides correct total balance after running script');
});
QUnit.start();
return QUnitGS2.getHtml();
}
function getResultsFromServer() {
return QUnitGS2.getResultsFromServer();
}
Where is mainSheet defined?
Also try deploying the web app, using the "latest code" can sometimes have unexpected effects.
Thanks for a quick reply.
That was a good remark about the mainSheet
. Although it is defined in the tested code file, the test code didn't "see" it. I've added its definition to the tests and now at least they call onClick
which does its job in the sheet.
Nevertheless, still no tests are shown as run and completed in the deployed web app (which I deploy instead of clicking latest code
as advised).
Any new insights in this topic?