From bcce8a6ad41983d58acf8898c541f67a5a812530 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Fri, 28 Jun 2024 22:35:03 +0000 Subject: [PATCH] Build commit bdcae8268719f3a0cd67a762f3f2e55a5985ac62 --- 404.html | 4 +- about/index.html | 4 +- api/QUnit/hooks/index.html | 6 +- api/QUnit/index.html | 4 +- api/QUnit/load/index.html | 4 +- api/QUnit/module/index.html | 4 +- api/QUnit/start/index.html | 4 +- api/QUnit/test.each/index.html | 4 +- api/QUnit/test.only/index.html | 4 +- api/QUnit/test.skip/index.html | 4 +- api/QUnit/test.todo/index.html | 4 +- api/QUnit/test/index.html | 4 +- api/assert/async/index.html | 4 +- api/assert/closeTo/index.html | 4 +- api/assert/deepEqual/index.html | 4 +- api/assert/equal/index.html | 4 +- api/assert/expect/index.html | 4 +- api/assert/false/index.html | 4 +- api/assert/index.html | 4 +- api/assert/notDeepEqual/index.html | 4 +- api/assert/notEqual/index.html | 4 +- api/assert/notOk/index.html | 4 +- api/assert/notPropContains/index.html | 4 +- api/assert/notPropEqual/index.html | 4 +- api/assert/notStrictEqual/index.html | 4 +- api/assert/ok/index.html | 4 +- api/assert/propContains/index.html | 4 +- api/assert/propEqual/index.html | 4 +- api/assert/push/index.html | 4 +- api/assert/pushResult/index.html | 6 +- api/assert/rejects/index.html | 4 +- api/assert/step/index.html | 4 +- api/assert/strictEqual/index.html | 4 +- api/assert/throws/index.html | 4 +- api/assert/timeout/index.html | 4 +- api/assert/true/index.html | 4 +- api/assert/verifySteps/index.html | 4 +- api/async/index.html | 4 +- api/callbacks/QUnit.begin/index.html | 4 +- api/callbacks/QUnit.done/index.html | 4 +- api/callbacks/QUnit.log/index.html | 4 +- api/callbacks/QUnit.moduleDone/index.html | 4 +- api/callbacks/QUnit.moduleStart/index.html | 4 +- api/callbacks/QUnit.on/index.html | 32 ++- api/callbacks/QUnit.testDone/index.html | 4 +- api/callbacks/QUnit.testStart/index.html | 4 +- api/callbacks/index.html | 4 +- api/config/altertitle/index.html | 8 +- api/config/autostart/index.html | 4 +- api/config/collapse/index.html | 6 +- api/config/current/index.html | 6 +- api/config/failOnZeroTests/index.html | 4 +- api/config/filter/index.html | 16 +- api/config/fixture/index.html | 165 +++++++++++- api/config/hidepassed/index.html | 20 +- api/config/index.html | 10 +- api/config/maxDepth/index.html | 4 +- api/config/module/index.html | 4 +- api/config/moduleId/index.html | 12 +- api/config/modules/index.html | 6 +- api/config/noglobals/index.html | 12 +- api/config/notrycatch/index.html | 15 +- api/config/reorder/index.html | 4 +- api/config/requireExpects/index.html | 4 +- api/config/scrolltop/index.html | 8 +- api/config/seed/index.html | 18 +- api/config/storage/index.html | 4 +- api/config/testId/index.html | 12 +- api/config/testTimeout/index.html | 4 +- api/config/urlConfig/index.html | 6 +- api/deprecated/index.html | 4 +- api/extension/QUnit.assert/index.html | 6 +- api/extension/QUnit.dump.parse/index.html | 6 +- api/extension/QUnit.extend/index.html | 6 +- .../QUnit.onUncaughtException/index.html | 6 +- api/extension/QUnit.stack/index.html | 6 +- api/extension/index.html | 9 +- api/index.html | 6 +- api/removed/index.html | 4 +- brand/index.html | 4 +- browser/index.html | 252 ++++++++++++++++++ cli/index.html | 4 +- cookbook/index.html | 8 +- feed.xml | 2 +- index.html | 10 +- intro/index.html | 106 +------- plugins/index.html | 4 +- projects/index.html | 12 +- redirects.json | 2 +- resources/calc.js | 42 +++ resources/calc.test.js | 25 ++ resources/example-add.html | 17 +- resources/example-index.html | 16 +- resources/game.js | 83 ++++++ resources/game.test.js | 60 +++++ upgrade-guide-2.x/index.html | 4 +- 96 files changed, 954 insertions(+), 322 deletions(-) create mode 100644 browser/index.html create mode 100644 resources/calc.js create mode 100644 resources/calc.test.js create mode 100644 resources/game.js create mode 100644 resources/game.test.js diff --git a/404.html b/404.html index 51e14a5c4..489d3ed26 100644 --- a/404.html +++ b/404.html @@ -17,8 +17,8 @@ +
diff --git a/api/config/fixture/index.html b/api/config/fixture/index.html index 6d5bc4f5f..48c25b477 100644 --- a/api/config/fixture/index.html +++ b/api/config/fixture/index.html @@ -6,7 +6,7 @@ QUnit.config.fixture | QUnit - + + +
+
+

Browser Runner

+
+
+
+

+ +Test JavaScript code in a real browser with QUnit. + +

+ +

Getting started

+ +

QUnit releases are standalone and require no runtime dependencies for use in the browser. To get started, all you need is an HTML file that loads two files: qunit.js and qunit.css.

+ +
<!DOCTYPE html>
+<html>
+<meta charset="utf-8">
+<title>QUnit</title>
+<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.21.0.css">
+<body>
+  <div id="qunit"></div>
+  <div id="qunit-fixture"></div>
+  <script src="https://code.jquery.com/qunit/qunit-2.21.0.js"></script>
+  <!-- <script src="your_app.test.js"></script> -->
+</body>
+</html>
+
+ +

This is typically saved as /test.html or /test/index.html in your project.

+ +

The above example loads QUnit from the jQuery CDN. For improved experience during local or offline development, it is recommended to install or download QUnit within your project. Some integrations, like Web Test Runner and Karma, can auto-create the HTML from a list of JS files or glob pattern.

+ +

Let’s add the following script, which tests an “add” function that adds two numbers together:

+ +
<script>
+function add(a, b) {
+  return a + b;
+}
+
+QUnit.module('add', function() {
+  QUnit.test('two numbers', function(assert) {
+    assert.equal(add(1, 2), 3);
+  });
+});
+</script>
+
+ +

Open your HTML file in a browser to find a detailed report. Live example (open in a new tab):

+ + + +

Congrats! You just executed your first QUnit test!

+ +

Fixture

+ +

Don’t worry about DOM changes from one test affecting other tests, because QUnit will automatically reset the markup after each test. As long as you append or insert your elements inside the fixture, you will never have to manually clean up after your tests.

+ +

This helps keep your tests them atomic!

+ +

Find examples and learn more at QUnit.config.fixture.

+ +

Integrations

+ +

Linting

+ +

The eslint-plugin-qunit package has a variety of rules available for enforcing best testing practices as well as detecting broken tests.

+ +

Browser automation

+ +

The following integrations can be used to automate the running of browser tests with QUnit:

+ + + +

Example projects:

+ +
    +
  • Krinkle/example-node-and-browser-qunit-ci: Run QUnit tests locally and in CI, on Headless Firefox and Chrome (using Karma), and with Node.js.
    Also demonstrates code coverage, and testing of isomorphic JavaScript projects.
  • +
+ +

URL parameters

+ + + +

Markup

+ +

QUnit requires no HTML markup in order to run tests. The above “Getting started” example is recommended for new projects, but you can customize this as-needed.

+ +

To display test results, the only markup necessary is a <div> with id="qunit". Without this, the tests will run with the HTML Reporter disabled.

+ +

Browser automations that run tests for you from the command-line, might enable other reporters or event listeners instead. For example, they might use a TAP reporter, or QUnit.on() to automatically extract results in a machine-readable way, and use it to set the build status of a continuous integration job (CI).

+ +

HTML Reporter

+ +

The header of the report displays:

+
    +
  • the page title.
  • +
  • a green bar when all tests passed, or a red bar if one or more tests failed.
  • +
  • the navigator.userAgent string, handy when comparing results captured from different browsers.
  • +
+ +

Toolbar

+ +

Hide passed tests is useful when a lot of tests ran and only a few failed. Ticking the checkbox will show only the tests that failed..

+ +

Check for globals detects if a test creates or removes global variable is. QUnit keeps a list of properties found on the window object. If properties were added or removed, the test fails.

+ +

No try-catch instructs QUnit to run your tests without a try-catch block. In this mode, if your test throws an error it will interrupt QUnit, which may ease debugging.

+ +

Filter

+ +

Enter a search phrase to re-run only tests that match the phrase. It performs a case-insensitive substring match by default, on both the module name and test name. You can use regular expressions, and/or invert the match to exclude tests instead.

+ +

Read filter for examples.

+ +

Module selector

+ +

To quickly re-run one or more modules of tests, select them from the module selector and press “Apply”.

+ +

You can use the input field to quickly find a module, even if you have many modules. The input field performs fuzzy matching, so don’t worry about getting it exactly right! baor game and boar dame finds “board game”. This is similar to how “Quick Open” works in modern text editors.

+ +

When selecting a parent module, which contains nested modules, the nested modules and their tests will also be run.

+ +

Test results

+ +

Each result is displayed in a numbered list. After the name of the test, in parentheses, are the number of failed, passed, and total assertions. Click the entry to show the results of each assertion, with details about expected and actual results (for failed asssertions).

+ +

The “Rerun” link at the end will run that test on its own.

+ +

Browser support

+ +

QUnit currently supports the following browsers:

+ +
    +
  • Internet Explorer: 9+
  • +
  • Edge: 15+ (both legacy MSEdge and Chromium-based)
  • +
  • Firefox: 45+
  • +
  • Safari: 9+
  • +
  • Opera: 36+
  • +
  • Chrome: 58+
  • +
  • Android: 4.3+
  • +
  • iOS: 7+ (Mobile Safari)
  • +
+ +

For older browsers, such as Internet Explorer 6-8, Opera 12+, or Safari 5+, please use QUnit 1.x, which you can download from the release archives.

+
+ + +
+ + diff --git a/cli/index.html b/cli/index.html index c4f140f37..60750b27b 100644 --- a/cli/index.html +++ b/cli/index.html @@ -17,8 +17,8 @@ +
diff --git a/plugins/index.html b/plugins/index.html index c2b01f7e5..5a52c4e3d 100644 --- a/plugins/index.html +++ b/plugins/index.html @@ -17,8 +17,8 @@ +
-

These organizations and open-source projects use QUnit to keep their code in check.

+

These organizations and open-source projects, and many others, use QUnit to keep their code in check.

Organizations

@@ -111,6 +111,12 @@

Khan Academy

Kiwix

kiwix-js

+
+

Square

+

ember-computable, +eslint-plugin-square, +qunit-bdd

+

Twitter

Hogan.js, diff --git a/redirects.json b/redirects.json index 1c763a348..09d5aca6d 100644 --- a/redirects.json +++ b/redirects.json @@ -1 +1 @@ -{"/config/QUnit.assert/":"https://qunitjs.com/api/extension/QUnit.assert/","/extension/QUnit.assert/":"https://qunitjs.com/api/extension/QUnit.assert/","/callbacks/QUnit.begin/":"https://qunitjs.com/api/callbacks/QUnit.begin/","/QUnit.begin/":"https://qunitjs.com/api/callbacks/QUnit.begin/","/callbacks/QUnit.done/":"https://qunitjs.com/api/callbacks/QUnit.done/","/QUnit.done/":"https://qunitjs.com/api/callbacks/QUnit.done/","/QUnit.dump.parse/":"https://qunitjs.com/api/extension/QUnit.dump.parse/","/QUnit.jsDump.parse/":"https://qunitjs.com/api/extension/QUnit.dump.parse/","/config/QUnit.dump.parse/":"https://qunitjs.com/api/extension/QUnit.dump.parse/","/extension/QUnit.dump.parse/":"https://qunitjs.com/api/extension/QUnit.dump.parse/","/config/QUnit.extend/":"https://qunitjs.com/api/extension/QUnit.extend/","/extension/QUnit.extend/":"https://qunitjs.com/api/extension/QUnit.extend/","/callbacks/QUnit.log/":"https://qunitjs.com/api/callbacks/QUnit.log/","/QUnit.log/":"https://qunitjs.com/api/callbacks/QUnit.log/","/callbacks/QUnit.moduleDone/":"https://qunitjs.com/api/callbacks/QUnit.moduleDone/","/QUnit.moduleDone/":"https://qunitjs.com/api/callbacks/QUnit.moduleDone/","/callbacks/QUnit.moduleStart/":"https://qunitjs.com/api/callbacks/QUnit.moduleStart/","/QUnit.moduleStart/":"https://qunitjs.com/api/callbacks/QUnit.moduleStart/","/callbacks/QUnit.on/":"https://qunitjs.com/api/callbacks/QUnit.on/","/config/QUnit.onUncaughtException/":"https://qunitjs.com/api/extension/QUnit.onUncaughtException/","/extension/QUnit.onUncaughtException/":"https://qunitjs.com/api/extension/QUnit.onUncaughtException/","/config/QUnit.stack/":"https://qunitjs.com/api/extension/QUnit.stack/","/extension/QUnit.stack/":"https://qunitjs.com/api/extension/QUnit.stack/","/callbacks/QUnit.testDone/":"https://qunitjs.com/api/callbacks/QUnit.testDone/","/QUnit.testDone/":"https://qunitjs.com/api/callbacks/QUnit.testDone/","/callbacks/QUnit.testStart/":"https://qunitjs.com/api/callbacks/QUnit.testStart/","/QUnit.testStart/":"https://qunitjs.com/api/callbacks/QUnit.testStart/","/config/altertitle/":"https://qunitjs.com/api/config/altertitle/","/assert/async/":"https://qunitjs.com/api/assert/async/","/QUnit.stop/":"https://qunitjs.com/api/assert/async/","/QUnit/stop/":"https://qunitjs.com/api/assert/async/","/stop/":"https://qunitjs.com/api/assert/async/","/async/":"https://qunitjs.com/api/async/","/config/autostart/":"https://qunitjs.com/api/config/autostart/","/node/":"https://qunitjs.com/cli/","/assert/closeTo/":"https://qunitjs.com/api/assert/closeTo/","/config/collapse/":"https://qunitjs.com/api/config/collapse/","/config/current/":"https://qunitjs.com/api/config/current/","/assert/deepEqual/":"https://qunitjs.com/api/assert/deepEqual/","/deepEqual/":"https://qunitjs.com/api/assert/deepEqual/","/deprecated/":"https://qunitjs.com/api/deprecated/","/equal/":"https://qunitjs.com/api/assert/equal/","/equals/":"https://qunitjs.com/api/assert/equal/","/assert/equal/":"https://qunitjs.com/api/assert/equal/","/assert/equals/":"https://qunitjs.com/api/assert/equal/","/assert/expect/":"https://qunitjs.com/api/assert/expect/","/expect/":"https://qunitjs.com/api/assert/expect/","/config/failOnZeroTests/":"https://qunitjs.com/api/config/failOnZeroTests/","/assert/false/":"https://qunitjs.com/api/assert/false/","/config/filter/":"https://qunitjs.com/api/config/filter/","/config/fixture/":"https://qunitjs.com/api/config/fixture/","/config/hidepassed/":"https://qunitjs.com/api/config/hidepassed/","/QUnit/hooks/":"https://qunitjs.com/api/QUnit/hooks/","/extension/":"https://qunitjs.com/api/extension/","/QUnit/":"https://qunitjs.com/api/QUnit/","/QUnit.config/":"https://qunitjs.com/api/config/","/config/":"https://qunitjs.com/api/config/","/config/QUnit.config/":"https://qunitjs.com/api/config/","/assert/":"https://qunitjs.com/api/assert/","/QUnit.assert/":"https://qunitjs.com/api/assert/","/category/assert/":"https://qunitjs.com/api/assert/","/callbacks/":"https://qunitjs.com/api/callbacks/","/category/callbacks/":"https://qunitjs.com/api/callbacks/","/category/all/":"https://qunitjs.com/api/","/guides/":"https://qunitjs.com/intro/","/cookbook/":"https://qunitjs.com/intro/","/QUnit/load/":"https://qunitjs.com/api/QUnit/load/","/config/maxDepth/":"https://qunitjs.com/api/config/maxDepth/","/QUnit.module/":"https://qunitjs.com/api/QUnit/module/","/QUnit/module/":"https://qunitjs.com/api/QUnit/module/","/module/":"https://qunitjs.com/api/QUnit/module/","/config/module/":"https://qunitjs.com/api/config/module/","/config/moduleId/":"https://qunitjs.com/api/config/moduleId/","/config/modules/":"https://qunitjs.com/api/config/modules/","/config/noglobals/":"https://qunitjs.com/api/config/noglobals/","/assert/notDeepEqual/":"https://qunitjs.com/api/assert/notDeepEqual/","/notDeepEqual/":"https://qunitjs.com/api/assert/notDeepEqual/","/assert/notEqual/":"https://qunitjs.com/api/assert/notEqual/","/notEqual/":"https://qunitjs.com/api/assert/notEqual/","/assert/notOk/":"https://qunitjs.com/api/assert/notOk/","/notOk/":"https://qunitjs.com/api/assert/notOk/","/assert/notPropContains/":"https://qunitjs.com/api/assert/notPropContains/","/assert/notPropEqual/":"https://qunitjs.com/api/assert/notPropEqual/","/notPropEqual/":"https://qunitjs.com/api/assert/notPropEqual/","/assert/notStrictEqual/":"https://qunitjs.com/api/assert/notStrictEqual/","/notStrictEqual/":"https://qunitjs.com/api/assert/notStrictEqual/","/config/notrycatch/":"https://qunitjs.com/api/config/notrycatch/","/assert/ok/":"https://qunitjs.com/api/assert/ok/","/ok/":"https://qunitjs.com/api/assert/ok/","/addons/":"https://qunitjs.com/plugins/","/assert/propContains/":"https://qunitjs.com/api/assert/propContains/","/assert/propEqual/":"https://qunitjs.com/api/assert/propEqual/","/propEqual/":"https://qunitjs.com/api/assert/propEqual/","/config/QUnit.push/":"https://qunitjs.com/api/assert/push/","/extension/QUnit.push/":"https://qunitjs.com/api/assert/push/","/api/extension/QUnit.push/":"https://qunitjs.com/api/assert/push/","/pushResult/":"https://qunitjs.com/api/assert/pushResult/","/assert/pushResult/":"https://qunitjs.com/api/assert/pushResult/","/assert/rejects/":"https://qunitjs.com/api/assert/rejects/","/removed/":"https://qunitjs.com/api/removed/","/config/reorder/":"https://qunitjs.com/api/config/reorder/","/config/requireExpects/":"https://qunitjs.com/api/config/requireExpects/","/config/scrolltop/":"https://qunitjs.com/api/config/scrolltop/","/config/seed/":"https://qunitjs.com/api/config/seed/","/QUnit/start/":"https://qunitjs.com/api/QUnit/start/","/start/":"https://qunitjs.com/api/QUnit/start/","/assert/step/":"https://qunitjs.com/api/assert/step/","/config/storage/":"https://qunitjs.com/api/config/storage/","/same/":"https://qunitjs.com/api/assert/strictEqual/","/strictEqual/":"https://qunitjs.com/api/assert/strictEqual/","/assert/same/":"https://qunitjs.com/api/assert/strictEqual/","/assert/strictEqual/":"https://qunitjs.com/api/assert/strictEqual/","/QUnit/test.each/":"https://qunitjs.com/api/QUnit/test.each/","/QUnit.asyncTest/":"https://qunitjs.com/api/QUnit/test/","/QUnit.test/":"https://qunitjs.com/api/QUnit/test/","/QUnit/test/":"https://qunitjs.com/api/QUnit/test/","/asyncTest/":"https://qunitjs.com/api/QUnit/test/","/test/":"https://qunitjs.com/api/QUnit/test/","/QUnit.only/":"https://qunitjs.com/api/QUnit/test.only/","/QUnit/only/":"https://qunitjs.com/api/QUnit/test.only/","/QUnit/test.only/":"https://qunitjs.com/api/QUnit/test.only/","/QUnit.skip/":"https://qunitjs.com/api/QUnit/test.skip/","/QUnit/skip/":"https://qunitjs.com/api/QUnit/test.skip/","/QUnit/test.skip/":"https://qunitjs.com/api/QUnit/test.skip/","/QUnit.todo/":"https://qunitjs.com/api/QUnit/test.todo/","/QUnit/todo/":"https://qunitjs.com/api/QUnit/test.todo/","/QUnit/test.todo/":"https://qunitjs.com/api/QUnit/test.todo/","/config/testId/":"https://qunitjs.com/api/config/testId/","/config/testTimeout/":"https://qunitjs.com/api/config/testTimeout/","/assert/raises/":"https://qunitjs.com/api/assert/throws/","/assert/throws/":"https://qunitjs.com/api/assert/throws/","/throws/":"https://qunitjs.com/api/assert/throws/","/assert/timeout/":"https://qunitjs.com/api/assert/timeout/","/assert/true/":"https://qunitjs.com/api/assert/true/","/config/urlConfig/":"https://qunitjs.com/api/config/urlConfig/","/assert/verifySteps/":"https://qunitjs.com/api/assert/verifySteps/"} \ No newline at end of file +{"/config/QUnit.assert/":"https://qunitjs.com/api/extension/QUnit.assert/","/extension/QUnit.assert/":"https://qunitjs.com/api/extension/QUnit.assert/","/callbacks/QUnit.begin/":"https://qunitjs.com/api/callbacks/QUnit.begin/","/QUnit.begin/":"https://qunitjs.com/api/callbacks/QUnit.begin/","/callbacks/QUnit.done/":"https://qunitjs.com/api/callbacks/QUnit.done/","/QUnit.done/":"https://qunitjs.com/api/callbacks/QUnit.done/","/QUnit.dump.parse/":"https://qunitjs.com/api/extension/QUnit.dump.parse/","/QUnit.jsDump.parse/":"https://qunitjs.com/api/extension/QUnit.dump.parse/","/config/QUnit.dump.parse/":"https://qunitjs.com/api/extension/QUnit.dump.parse/","/extension/QUnit.dump.parse/":"https://qunitjs.com/api/extension/QUnit.dump.parse/","/config/QUnit.extend/":"https://qunitjs.com/api/extension/QUnit.extend/","/extension/QUnit.extend/":"https://qunitjs.com/api/extension/QUnit.extend/","/callbacks/QUnit.log/":"https://qunitjs.com/api/callbacks/QUnit.log/","/QUnit.log/":"https://qunitjs.com/api/callbacks/QUnit.log/","/callbacks/QUnit.moduleDone/":"https://qunitjs.com/api/callbacks/QUnit.moduleDone/","/QUnit.moduleDone/":"https://qunitjs.com/api/callbacks/QUnit.moduleDone/","/callbacks/QUnit.moduleStart/":"https://qunitjs.com/api/callbacks/QUnit.moduleStart/","/QUnit.moduleStart/":"https://qunitjs.com/api/callbacks/QUnit.moduleStart/","/callbacks/QUnit.on/":"https://qunitjs.com/api/callbacks/QUnit.on/","/config/QUnit.onUncaughtException/":"https://qunitjs.com/api/extension/QUnit.onUncaughtException/","/extension/QUnit.onUncaughtException/":"https://qunitjs.com/api/extension/QUnit.onUncaughtException/","/config/QUnit.stack/":"https://qunitjs.com/api/extension/QUnit.stack/","/extension/QUnit.stack/":"https://qunitjs.com/api/extension/QUnit.stack/","/callbacks/QUnit.testDone/":"https://qunitjs.com/api/callbacks/QUnit.testDone/","/QUnit.testDone/":"https://qunitjs.com/api/callbacks/QUnit.testDone/","/callbacks/QUnit.testStart/":"https://qunitjs.com/api/callbacks/QUnit.testStart/","/QUnit.testStart/":"https://qunitjs.com/api/callbacks/QUnit.testStart/","/config/altertitle/":"https://qunitjs.com/api/config/altertitle/","/assert/async/":"https://qunitjs.com/api/assert/async/","/QUnit.stop/":"https://qunitjs.com/api/assert/async/","/QUnit/stop/":"https://qunitjs.com/api/assert/async/","/stop/":"https://qunitjs.com/api/assert/async/","/async/":"https://qunitjs.com/api/async/","/config/autostart/":"https://qunitjs.com/api/config/autostart/","/cookbook/":"https://qunitjs.com/browser/","/node/":"https://qunitjs.com/cli/","/assert/closeTo/":"https://qunitjs.com/api/assert/closeTo/","/config/collapse/":"https://qunitjs.com/api/config/collapse/","/config/current/":"https://qunitjs.com/api/config/current/","/assert/deepEqual/":"https://qunitjs.com/api/assert/deepEqual/","/deepEqual/":"https://qunitjs.com/api/assert/deepEqual/","/deprecated/":"https://qunitjs.com/api/deprecated/","/equal/":"https://qunitjs.com/api/assert/equal/","/equals/":"https://qunitjs.com/api/assert/equal/","/assert/equal/":"https://qunitjs.com/api/assert/equal/","/assert/equals/":"https://qunitjs.com/api/assert/equal/","/assert/expect/":"https://qunitjs.com/api/assert/expect/","/expect/":"https://qunitjs.com/api/assert/expect/","/config/failOnZeroTests/":"https://qunitjs.com/api/config/failOnZeroTests/","/assert/false/":"https://qunitjs.com/api/assert/false/","/config/filter/":"https://qunitjs.com/api/config/filter/","/config/fixture/":"https://qunitjs.com/api/config/fixture/","/config/hidepassed/":"https://qunitjs.com/api/config/hidepassed/","/QUnit/hooks/":"https://qunitjs.com/api/QUnit/hooks/","/callbacks/":"https://qunitjs.com/api/callbacks/","/category/callbacks/":"https://qunitjs.com/api/callbacks/","/QUnit/":"https://qunitjs.com/api/QUnit/","/extension/":"https://qunitjs.com/api/extension/","/assert/":"https://qunitjs.com/api/assert/","/QUnit.assert/":"https://qunitjs.com/api/assert/","/category/assert/":"https://qunitjs.com/api/assert/","/QUnit.config/":"https://qunitjs.com/api/config/","/config/":"https://qunitjs.com/api/config/","/config/QUnit.config/":"https://qunitjs.com/api/config/","/category/all/":"https://qunitjs.com/api/","/guides/":"https://qunitjs.com/intro/","/QUnit/load/":"https://qunitjs.com/api/QUnit/load/","/config/maxDepth/":"https://qunitjs.com/api/config/maxDepth/","/QUnit.module/":"https://qunitjs.com/api/QUnit/module/","/QUnit/module/":"https://qunitjs.com/api/QUnit/module/","/module/":"https://qunitjs.com/api/QUnit/module/","/config/module/":"https://qunitjs.com/api/config/module/","/config/moduleId/":"https://qunitjs.com/api/config/moduleId/","/config/modules/":"https://qunitjs.com/api/config/modules/","/config/noglobals/":"https://qunitjs.com/api/config/noglobals/","/assert/notDeepEqual/":"https://qunitjs.com/api/assert/notDeepEqual/","/notDeepEqual/":"https://qunitjs.com/api/assert/notDeepEqual/","/assert/notEqual/":"https://qunitjs.com/api/assert/notEqual/","/notEqual/":"https://qunitjs.com/api/assert/notEqual/","/assert/notOk/":"https://qunitjs.com/api/assert/notOk/","/notOk/":"https://qunitjs.com/api/assert/notOk/","/assert/notPropContains/":"https://qunitjs.com/api/assert/notPropContains/","/assert/notPropEqual/":"https://qunitjs.com/api/assert/notPropEqual/","/notPropEqual/":"https://qunitjs.com/api/assert/notPropEqual/","/assert/notStrictEqual/":"https://qunitjs.com/api/assert/notStrictEqual/","/notStrictEqual/":"https://qunitjs.com/api/assert/notStrictEqual/","/config/notrycatch/":"https://qunitjs.com/api/config/notrycatch/","/assert/ok/":"https://qunitjs.com/api/assert/ok/","/ok/":"https://qunitjs.com/api/assert/ok/","/addons/":"https://qunitjs.com/plugins/","/assert/propContains/":"https://qunitjs.com/api/assert/propContains/","/assert/propEqual/":"https://qunitjs.com/api/assert/propEqual/","/propEqual/":"https://qunitjs.com/api/assert/propEqual/","/config/QUnit.push/":"https://qunitjs.com/api/assert/push/","/extension/QUnit.push/":"https://qunitjs.com/api/assert/push/","/api/extension/QUnit.push/":"https://qunitjs.com/api/assert/push/","/pushResult/":"https://qunitjs.com/api/assert/pushResult/","/assert/pushResult/":"https://qunitjs.com/api/assert/pushResult/","/assert/rejects/":"https://qunitjs.com/api/assert/rejects/","/removed/":"https://qunitjs.com/api/removed/","/config/reorder/":"https://qunitjs.com/api/config/reorder/","/config/requireExpects/":"https://qunitjs.com/api/config/requireExpects/","/config/scrolltop/":"https://qunitjs.com/api/config/scrolltop/","/config/seed/":"https://qunitjs.com/api/config/seed/","/QUnit/start/":"https://qunitjs.com/api/QUnit/start/","/start/":"https://qunitjs.com/api/QUnit/start/","/assert/step/":"https://qunitjs.com/api/assert/step/","/config/storage/":"https://qunitjs.com/api/config/storage/","/same/":"https://qunitjs.com/api/assert/strictEqual/","/strictEqual/":"https://qunitjs.com/api/assert/strictEqual/","/assert/same/":"https://qunitjs.com/api/assert/strictEqual/","/assert/strictEqual/":"https://qunitjs.com/api/assert/strictEqual/","/QUnit/test.each/":"https://qunitjs.com/api/QUnit/test.each/","/QUnit.asyncTest/":"https://qunitjs.com/api/QUnit/test/","/QUnit.test/":"https://qunitjs.com/api/QUnit/test/","/QUnit/test/":"https://qunitjs.com/api/QUnit/test/","/asyncTest/":"https://qunitjs.com/api/QUnit/test/","/test/":"https://qunitjs.com/api/QUnit/test/","/QUnit.only/":"https://qunitjs.com/api/QUnit/test.only/","/QUnit/only/":"https://qunitjs.com/api/QUnit/test.only/","/QUnit/test.only/":"https://qunitjs.com/api/QUnit/test.only/","/QUnit.skip/":"https://qunitjs.com/api/QUnit/test.skip/","/QUnit/skip/":"https://qunitjs.com/api/QUnit/test.skip/","/QUnit/test.skip/":"https://qunitjs.com/api/QUnit/test.skip/","/QUnit.todo/":"https://qunitjs.com/api/QUnit/test.todo/","/QUnit/todo/":"https://qunitjs.com/api/QUnit/test.todo/","/QUnit/test.todo/":"https://qunitjs.com/api/QUnit/test.todo/","/config/testId/":"https://qunitjs.com/api/config/testId/","/config/testTimeout/":"https://qunitjs.com/api/config/testTimeout/","/assert/raises/":"https://qunitjs.com/api/assert/throws/","/assert/throws/":"https://qunitjs.com/api/assert/throws/","/throws/":"https://qunitjs.com/api/assert/throws/","/assert/timeout/":"https://qunitjs.com/api/assert/timeout/","/assert/true/":"https://qunitjs.com/api/assert/true/","/config/urlConfig/":"https://qunitjs.com/api/config/urlConfig/","/assert/verifySteps/":"https://qunitjs.com/api/assert/verifySteps/"} \ No newline at end of file diff --git a/resources/calc.js b/resources/calc.js new file mode 100644 index 000000000..da6da2bee --- /dev/null +++ b/resources/calc.js @@ -0,0 +1,42 @@ +/** + * calc.js - An example project to demonstrate QUnit. + * + * @author Timo Tijhof, 2022 + * @license 0BSD + * @license Public domain + */ + +/** + * @param {number} a + * @param {number} b + * @return {number} + */ +export function add (a, b) { + return a + b; +} + +/** + * @param {number} a + * @param {number} b + * @return {number} + */ +export function substract (a, b) { + return a - b; +} + +/** + * @param {number} a + * @param {number} b + * @return {number} + */ +export function multiply (a, b) { + return a * b; +} + +/** + * @param {number} x + * @return {number} + */ +export function square (x) { + return x * x; +} diff --git a/resources/calc.test.js b/resources/calc.test.js new file mode 100644 index 000000000..12b2014a2 --- /dev/null +++ b/resources/calc.test.js @@ -0,0 +1,25 @@ +import * as calc from './calc.js'; + +QUnit.module('calc', () => { + QUnit.test('add', (assert) => { + assert.equal(calc.add(1, 2), 3); + assert.equal(calc.add(2, 3), 5); + assert.equal(calc.add(5, -1), 4, 'negative'); + }); + + QUnit.test('substract', (assert) => { + assert.equal(calc.substract(3, 2), 1); + assert.equal(calc.substract(5, 3), 2); + assert.equal(calc.substract(5, -1), 6, 'negative'); + }); + + QUnit.test('multiply', (assert) => { + assert.equal(calc.multiply(7, 2), 14); + }); + + QUnit.test('square', (assert) => { + assert.equal(calc.square(5), 25); + assert.equal(calc.square(7), 49); + assert.equal(calc.square(-8), 64, 'negative'); + }); +}); diff --git a/resources/example-add.html b/resources/example-add.html index b7490faed..c828dd1ad 100644 --- a/resources/example-add.html +++ b/resources/example-add.html @@ -1,4 +1,5 @@ + QUnit @@ -7,14 +8,16 @@

+ diff --git a/resources/example-index.html b/resources/example-index.html index afb5ddbae..71afc7832 100644 --- a/resources/example-index.html +++ b/resources/example-index.html @@ -1,20 +1,14 @@ + QUnit
+ - + + - + diff --git a/resources/game.js b/resources/game.js new file mode 100644 index 000000000..bbf86e42e --- /dev/null +++ b/resources/game.js @@ -0,0 +1,83 @@ +/** + * game.js - An example project to demonstrate QUnit. + * + * @author Timo Tijhof, 2022 + * @license 0BSD + * @license Public domain + */ + +export class Robot {} + +export class BoardObjectError extends Error {} +export class BoardMoveError extends Error {} + +export class Coord { + constructor (x = 0, y = 0) { + this.x = x; + this.y = y; + } + + clone () { + return new Coord(this.x, this.y); + } +} + +export class Board { + constructor (width, height) { + this.xMax = width - 1; + this.yMax = height - 1; + this.objects = new Map(); + } + + add (object) { + if (this.objects.has(object)) { + throw new BoardObjectError('Object already on board'); + } + this.objects.set(object, new Coord()); + } + + find (object) { + const pos = this.objects.get(object); + return pos ? pos.clone() : false; + } + + moveUp (object) { + const pos = this.objects.get(object); + if (!pos) { + throw new BoardObjectError('Object not on board'); + } + const newPos = pos.clone(); + newPos.y = (newPos.y === 0) ? this.yMax : (newPos.y - 1); + this.objects.set(object, this.normalizeCoord(newPos)); + } + + moveDown (object) { + const pos = this.objects.get(object); + if (!pos) { + throw new BoardObjectError('Object not on board'); + } + const newPos = pos.clone(); + newPos.y = (newPos.y === this.yMax) ? 0 : (newPos.y + 1); + this.objects.set(object, newPos); + } + + moveLeft (object) { + const pos = this.objects.get(object); + if (!pos) { + throw new BoardObjectError('Object not on board'); + } + const newPos = pos.clone(); + newPos.x = (newPos.x === 0) ? this.xMax : (newPos.x - 1); + this.objects.set(object, newPos); + } + + moveRight (object) { + const pos = this.objects.get(object); + if (!pos) { + throw new BoardObjectError('Object not on board'); + } + const newPos = pos.clone(); + newPos.x = (newPos.x === this.xMax) ? 0 : (newPos.x + 1); + this.objects.set(object, newPos); + } +} diff --git a/resources/game.test.js b/resources/game.test.js new file mode 100644 index 000000000..27d7849c4 --- /dev/null +++ b/resources/game.test.js @@ -0,0 +1,60 @@ +import * as game from './game.js'; + +QUnit.module('game', (hooks) => { + let board; + + hooks.beforeEach(() => { + board = new game.Board(3, 3); + }); + + QUnit.module('Coord', () => { + QUnit.test('constructor', (assert) => { + const pos1 = new game.Coord(); + assert.propContains(pos1, { x: 0, y: 0 }, 'defaults'); + + const pos2 = new game.Coord(5, 7); + assert.propContains(pos2, { x: 5, y: 7 }, 'parameters'); + }); + }); + + QUnit.module('Board', () => { + QUnit.test('add', (assert) => { + const alice = new game.Robot(); + board.add(alice); + assert.propContains(board.find(alice), { x: 0, y: 0 }, 'add alice'); + + const bob = new game.Robot(); + board.add(bob); + assert.propContains(board.find(bob), { x: 0, y: 0 }, 'add bob'); + + assert.throws(() => { + board.add(bob); + }, game.BoardObjectError, 'add second bob'); + }); + + QUnit.test('find [absent]', (assert) => { + const bob = new game.Robot(); + assert.false(board.find(bob)); + }); + + QUnit.test('move', (assert) => { + const alice = new game.Robot(); + board.add(alice); + + board.moveRight(alice); + assert.propContains(board.find(alice), { x: 1, y: 0 }, 'move'); + + board.moveRight(alice); + assert.propContains(board.find(alice), { x: 2, y: 0 }, 'move again'); + + board.moveRight(alice); + assert.propContains(board.find(alice), { x: 0, y: 0 }, 'teleport back'); + + const bob = new game.Robot(); + + assert.throws(() => { + board.moveRight(bob); + }, board.BoardObjectError, 'not on board'); + }); + }); +}); diff --git a/upgrade-guide-2.x/index.html b/upgrade-guide-2.x/index.html index f2ef2f94a..6fc8f68ce 100644 --- a/upgrade-guide-2.x/index.html +++ b/upgrade-guide-2.x/index.html @@ -17,8 +17,8 @@ +