Skip to content

Commit

Permalink
Test: Cover failure branches of QUnit.on
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Jul 11, 2024
1 parent 51bc981 commit 2d227e1
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ module.exports = function (grunt) {
'test/main/diff.js',
'test/main/dump.js',
'test/main/each.js',
'test/main/events.js',
'test/main/HtmlReporter.js',
'test/main/modules.js',
'test/main/modules-es2018.js',
Expand Down
1 change: 1 addition & 0 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const MEMORY_EVENTS = [
* @return {void}
*/
export function emit (eventName, data) {
/* istanbul ignore if: private function */
if (typeof eventName !== 'string') {
throw new TypeError('eventName must be a string when emitting an event');
}
Expand Down
1 change: 1 addition & 0 deletions test/index-es5.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<script src="main/diff.js"></script>
<script src="main/dump.js"></script>
<script src="main/each.js"></script>
<script src="main/events.js"></script>
<script src="main/HtmlReporter.js"></script>
<script src="main/legacy.js"></script>
<script src="main/modules.js"></script>
Expand Down
1 change: 1 addition & 0 deletions test/index-xhtml.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<script src="main/diff.js"></script>
<script src="main/dump.js"></script>
<script src="main/each.js"></script>
<script src="main/events.js"></script>
<script src="main/HtmlReporter.js"></script>
<script src="main/legacy.js"></script>
<script src="main/modules-es2018.js"></script>
Expand Down
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<script src="main/diff.js"></script>
<script src="main/dump.js"></script>
<script src="main/each.js"></script>
<script src="main/events.js"></script>
<script src="main/HtmlReporter.js"></script>
<script src="main/legacy.js"></script>
<script src="main/modules-es2018.js"></script>
Expand Down
4 changes: 4 additions & 0 deletions test/main/assert-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ QUnit.module('assert.step', function () {
assert.verifySteps(['two']);
});

QUnit.test('empty verifySteps()', function (assert) {
assert.verifySteps([]);
});

QUnit.test('errors if not called when `assert.step` is used', function (assert) {
assert.expect(2);
assert.step('one');
Expand Down
25 changes: 25 additions & 0 deletions test/main/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
QUnit.module('events', function () {
QUnit.test('QUnit.on [failure]', function (assert) {
assert.throws(function () {
QUnit.on(null, function () {
assert.step('null called');
});
}, /must be a string/, 'null event name');

assert.throws(function () {
QUnit.on('banana', function () {
assert.step('banana called');
});
}, /not a valid event/, 'unknown event name');

assert.throws(function () {
QUnit.on('runStart');
}, /must be a function/, 'missing callback');

assert.throws(function () {
QUnit.on('runStart', null);
}, /must be a function/, 'null callback');

assert.verifySteps([]);
});
});
1 change: 1 addition & 0 deletions test/mozjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ loadRelativeToScript('../test/main/deepEqual.js');
loadRelativeToScript('../test/main/diff.js');
loadRelativeToScript('../test/main/dump.js');
loadRelativeToScript('../test/main/each.js');
loadRelativeToScript('../test/main/events.js');
loadRelativeToScript('../test/main/HtmlReporter.js');
// loadRelativeToScript( "../test/main/modules.js" ); // Requires setTimeout
loadRelativeToScript('../test/main/modules-es2018.js');
Expand Down
1 change: 1 addition & 0 deletions test/mozjs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '../test/main/deepEqual.js';
import '../test/main/diff.js';
import '../test/main/dump.js';
import '../test/main/each.js';
import '../test/main/events.js';
import '../test/main/HtmlReporter.js';
// import "../test/main/modules.js"; // Requires setTimeout
import '../test/main/modules-es2018.js';
Expand Down
1 change: 1 addition & 0 deletions test/webWorker-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ importScripts(
'main/diff.js',
'main/dump.js',
'main/each.js',
'main/events.js',
'main/HtmlReporter.js',
'main/modules.js',
'main/modules-es2018.js',
Expand Down

0 comments on commit 2d227e1

Please sign in to comment.