Skip to content

Testing

You can write unit tests for your JSA extension logic using standard JavaScript testing tools. We recommend QUnit for its simplicity — no build step required, runs in the browser, and the learning curve is gentle.

If you’re coming from Ruby, you know the value of tests. The same applies here: tests catch regressions, document behavior, and give you confidence when refactoring. Even a few tests covering your core logic save time in the long run.

Focus on testing your extension’s business logic — the functions that process data, make decisions, or transform model information. You typically won’t test the SketchUp API calls themselves (that’s our job), but you can test the logic around them.

For example, if your extension calculates material coverage or generates a report from entity data, those calculations are great candidates for tests.

Create a test HTML file that loads QUnit and your extension’s logic:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My Extension Tests</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.20.1.css">
</head>
<body>
<div id="qunit"></div>
<script src="https://code.jquery.com/qunit/qunit-2.20.1.js"></script>
<script type="module">
// Import your extension's logic
// import { calculateArea, formatReport } from './src/helpers.js';
// Example: testing a helper function
function calculateTotalArea(faces) {
return faces.reduce((sum, face) => sum + face.area, 0);
}
QUnit.module('calculateTotalArea', function() {
QUnit.test('sums face areas correctly', function(assert) {
const faces = [
{ area: 100 },
{ area: 250 },
{ area: 50 },
];
assert.equal(calculateTotalArea(faces), 400);
});
QUnit.test('returns 0 for empty array', function(assert) {
assert.equal(calculateTotalArea([]), 0);
});
});
</script>
</body>
</html>

Open this file in a browser to run the tests. No server needed — just double-click it.

  • Separate logic from API calls. Put your calculation and transformation logic in separate functions (or a separate file) that you can test independently of SketchUpApi.
  • Mock sparingly. If a function takes entity data as input and returns a result, you can pass in plain objects that look like entities without needing a real SketchUp connection.
  • Start small. Even 3-4 tests covering your core helper functions add real value.