QUnitGS2 icon indicating copy to clipboard operation
QUnitGS2 copied to clipboard

Error: QUnit is not defined

Open dlealv opened this issue 3 years ago • 3 comments

First of all, thank you for creating this tool. I am following the instructions you provided: http://qunitgs2.com/examples/step-by-step-tutorial

I was able to install version 23 using the ID you provided.

When I enter the code for specifying the test cases I am getting the following error:

ReferenceError: QUnit is not defined (line 17, file "Tests")

The line refers to the following portion of the source code:

QUnit.module("reviewBugInfo tests");

This is the QUnit version: QUnit v2.9.2 for Google Apps Script

I was not able to find this error on the internet.

Please advise,

Thanks

dlealv avatar Sep 12 '21 04:09 dlealv

Hi. Take a look at the test code here. QUnit is something you define in your own test code. And note the comment at the top about code ordering.

andrewroberts avatar Sep 12 '21 11:09 andrewroberts

Thanks Andrew, this is the source code of my Tests.gs source file:

var Qunit = QUnitGS2.QUnit;

// HTML get function
function doGet() {
   QUnitGS2.init();

 /**
   * reviewBugInfo(jiraStatus, release, environment, rootCause, severity, status, resolution)
   * 
   */

  QUnit.module("reviewBugInfo tests");
  QUnit.test("Missing Mandatory fields", function( assert ) {
    assert.equal(reviewBugInfo("To Do", "release1", "env1", "rootCause1", "severity1", "status1", null), 
      null, "All mandatory fields have value");
  });

  // The following portion of the source code should not be changed

   Qunit.start();
   return QUnitGS2.getHtml();
}

// Retrieve test results when ready.
function getResultsFromServer() {
   return QUnitGS2.getResultsFromServer();
}

it uses the same logic as the source code you shared. The order of my files is the following:

Tests.gs
Code.gs

When I comment on the block for doing the testing

QUnit.module("reviewBugInfo tests");
  QUnit.test("Missing Mandatory fields", function( assert ) {
    assert.equal(reviewBugInfo("To Do", "release1", "env1", "rootCause1", "severity1", "status1", null), 
      null, "All mandatory fields have value");
  });

I got the following result, which is the same you in your tutorial, when there are not tests defined:

QUnit v2.9.2 for Google Apps Script Hide passed tests QUnit (Google Apps Script port); Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 Tests completed in milliseconds. assertions of passed failed.

Please advise,

Thanks,

David

dlealv avatar Sep 12 '21 19:09 dlealv

I removed the semicolon at the end here, and it works:

QUnit.module("reviewBugInfo tests");
  QUnit.test("Missing Mandatory fields", function( assert ) {
    assert.equal(reviewBugInfo("To Do", "release1", "env1", "rootCause1", "severity1", "status1", null), 
      null, "All mandatory fields have value");
  }); 

The response, still indicates it is running QUnit 2.9.2

Thanks,

David

dlealv avatar Sep 12 '21 20:09 dlealv