forked from qunitjs/qunit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: Migrate api docs (qunitjs#1135)
- Loading branch information
Showing
56 changed files
with
2,802 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ node_modules | |
build/report | ||
browserstack-run.pid | ||
temp/ | ||
docs/_site/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
api.qunitjs.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Welcome! Thanks for your interest in contributing to api.qunitjs.com. You're **almost** in the right place. More information on how to contribute to this and all other jQuery Foundation projects is over at [contribute.jquery.org](http://contribute.jquery.org). You'll definitely want to take a look at the articles on contributing [documentation](http://contribute.jquery.org/documentation). | ||
|
||
You may also want to take a look at our [commit & pull request guide](http://contribute.jquery.org/commits-and-pull-requests/) and [style guides](http://contribute.jquery.org/style-guide/) for instructions on how to maintain your fork and submit your code. Before we can merge any pull request, we'll also need you to sign our [contributor license agreement](http://contribute.jquery.org/cla). | ||
|
||
You can find us on [IRC](http://irc.jquery.org), specifically in #jquery-content should you have any questions. If you've never contributed to open source before, we've put together [a short guide with tips, tricks, and ideas on getting started](http://contribute.jquery.org/open-source/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
source "https://rubygems.org" | ||
ruby RUBY_VERSION | ||
|
||
# Hello! This is where you manage which Jekyll version is used to run. | ||
# When you want to use a different version, change it below, save the | ||
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so: | ||
# | ||
# bundle exec jekyll serve | ||
# | ||
# This will help ensure the proper Jekyll version is running. | ||
# Happy Jekylling! | ||
gem "jekyll", "3.4.3" | ||
|
||
# This is the default theme for new Jekyll sites. You may change this to anything you like. | ||
gem "minima", "~> 2.0" | ||
|
||
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and | ||
# uncomment the line below. To upgrade, run `bundle update github-pages`. | ||
# gem "github-pages", group: :jekyll_plugins | ||
|
||
# If you have any plugins, put them here! | ||
group :jekyll_plugins do | ||
gem "jekyll-feed", "~> 0.6" | ||
end | ||
|
||
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem | ||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
addressable (2.5.1) | ||
public_suffix (~> 2.0, >= 2.0.2) | ||
colorator (1.1.0) | ||
ffi (1.9.18) | ||
forwardable-extended (2.6.0) | ||
jekyll (3.4.3) | ||
addressable (~> 2.4) | ||
colorator (~> 1.0) | ||
jekyll-sass-converter (~> 1.0) | ||
jekyll-watch (~> 1.1) | ||
kramdown (~> 1.3) | ||
liquid (~> 3.0) | ||
mercenary (~> 0.3.3) | ||
pathutil (~> 0.9) | ||
rouge (~> 1.7) | ||
safe_yaml (~> 1.0) | ||
jekyll-feed (0.9.2) | ||
jekyll (~> 3.3) | ||
jekyll-sass-converter (1.5.0) | ||
sass (~> 3.4) | ||
jekyll-watch (1.5.0) | ||
listen (~> 3.0, < 3.1) | ||
kramdown (1.13.2) | ||
liquid (3.0.6) | ||
listen (3.0.8) | ||
rb-fsevent (~> 0.9, >= 0.9.4) | ||
rb-inotify (~> 0.9, >= 0.9.7) | ||
mercenary (0.3.6) | ||
minima (2.1.0) | ||
jekyll (~> 3.3) | ||
pathutil (0.14.0) | ||
forwardable-extended (~> 2.6) | ||
public_suffix (2.0.5) | ||
rb-fsevent (0.9.8) | ||
rb-inotify (0.9.8) | ||
ffi (>= 0.5.0) | ||
rouge (1.11.1) | ||
safe_yaml (1.0.4) | ||
sass (3.4.23) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
jekyll (= 3.4.3) | ||
jekyll-feed (~> 0.6) | ||
minima (~> 2.0) | ||
tzinfo-data | ||
|
||
RUBY VERSION | ||
ruby 2.4.1p111 | ||
|
||
BUNDLED WITH | ||
1.14.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
layout: page | ||
title: Main assertions | ||
category: main | ||
categories: | ||
- topics | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,268 @@ | ||
--- | ||
layout: default | ||
title: module | ||
description: Group related tests under a single label. | ||
categories: | ||
- main | ||
--- | ||
|
||
## `QUnit.module( name [, hooks] [, nested ] )` | ||
|
||
Group related tests under a single label. | ||
|
||
| parameter | description | | ||
|-----------|-------------| | ||
| `name` (string) | Label for this group of tests. | | ||
| `hooks` (object) | Callbacks to run during test execution. | | ||
| `nested` (function) | A callback used for nested modules. | | ||
|
||
#### hooks properties: `{ before, beforeEach, afterEach, after }` | ||
|
||
| name | description | | ||
|-----------|-------------| | ||
| `before` (function) | Runs before the first test. | | ||
| `beforeEach` (function) | Runs before each test. | | ||
| `afterEach` (function) | Runs after each test. | | ||
| `after` (function) | Runs after the last test. | | ||
|
||
> Note: If additional tests are defined after the module's queue has emptied, it will not run the `after` hook again. | ||
#### Nested module: `nested( hooks )` | ||
|
||
A callback with grouped tests and nested modules to run under the current module label. | ||
|
||
| name | description | | ||
|-----------|-------------| | ||
| `hooks` (object) | Runs before the first test. | | ||
|
||
### Description | ||
|
||
You can use the module name to organize, select, and filter tests to run. | ||
|
||
All tests inside a module callback function will be grouped into that module. The test names will all be preceded by the module name in the test results. Other modules can be nested inside this callback function, where their tests' names will be labeled by their names recursively prefixed by their parent modules. | ||
|
||
If `QUnit.module` is defined without a `nested` callback argument, all subsequently defined tests will be grouped into the module until another module is defined. | ||
|
||
Modules with test group functions allow you to define nested modules, and QUnit will run tests on the parent module before going deep on the nested ones, even if they're declared first. Additionally, any hook callbacks on a parent module will wrap the hooks on a nested module. In other words, `before` and `beforeEach` callbacks will form a [queue][] while the `afterEach` and `after` callbacks will form a [stack][]. | ||
|
||
[queue]: https://en.wikipedia.org/wiki/Queue_%28abstract_data_type%29 | ||
[stack]: https://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29 | ||
|
||
You can specify code to run before and after tests using the hooks argument, and also to create properties that will be shared on the testing context. Any additional properties on the `hooks` object will be added to that context. The `hooks` argument is still optional if you call `QUnit.module` with a callback argument. | ||
|
||
The module's callback is invoked with the test environment as its `this` context, with the environment's properties copied to the module's tests, hooks, and nested modules. Note that changes on tests' `this` are not preserved between sibling tests, where `this` will be reset to the initial value for each test. | ||
|
||
`QUnit.module()`'s hooks can automatically handle the asynchronous resolution of a Promise on your behalf if you return a `then`able Promise as the result of your callback function. | ||
|
||
### Examples | ||
|
||
Use the `QUnit.module()` function to group tests together: | ||
|
||
```js | ||
QUnit.module( "group a" ); | ||
QUnit.test( "a basic test example", function( assert ) { | ||
assert.ok( true, "this test is fine" ); | ||
}); | ||
QUnit.test( "a basic test example 2", function( assert ) { | ||
assert.ok( true, "this test is fine" ); | ||
}); | ||
|
||
QUnit.module( "group b" ); | ||
QUnit.test( "a basic test example 3", function( assert ) { | ||
assert.ok( true, "this test is fine" ); | ||
}); | ||
QUnit.test( "a basic test example 4", function( assert ) { | ||
assert.ok( true, "this test is fine" ); | ||
}); | ||
``` | ||
|
||
Using modern syntax: | ||
|
||
```js | ||
const { test } = QUnit; | ||
QUnit.module( "group a" ); | ||
|
||
test( "a basic test example", t => { | ||
t.ok( true, "this test is fine" ); | ||
}); | ||
test( "a basic test example 2", t => { | ||
t.ok( true, "this test is fine" ); | ||
}); | ||
|
||
QUnit.module( "group b" ); | ||
test( "a basic test example 3", t => { | ||
t.ok( true, "this test is fine" ); | ||
}); | ||
test( "a basic test example 4", t => { | ||
t.ok( true, "this test is fine" ); | ||
}); | ||
``` | ||
|
||
--- | ||
|
||
Use the `QUnit.module()` function to group tests together: | ||
|
||
```js | ||
QUnit.module( "module a", function() { | ||
QUnit.test( "a basic test example", function( assert ) { | ||
assert.ok( true, "this test is fine" ); | ||
}); | ||
}); | ||
|
||
QUnit.module( "module b", function() { | ||
QUnit.test( "a basic test example 2", function( assert ) { | ||
assert.ok( true, "this test is fine" ); | ||
}); | ||
|
||
QUnit.module( "nested module b.1", function() { | ||
|
||
// This test will be prefixed with the following module label: | ||
// "module b > nested module b.1" | ||
QUnit.test( "a basic test example 3", function( assert ) { | ||
assert.ok( true, "this test is fine" ); | ||
}); | ||
}); | ||
}); | ||
``` | ||
|
||
Using modern syntax: | ||
|
||
```js | ||
const { test } = QUnit; | ||
QUnit.module( "module a", () => { | ||
test( "a basic test example", t => { | ||
t.ok( true, "this test is fine" ); | ||
}); | ||
}); | ||
|
||
QUnit.module( "module b", () => { | ||
test( "a basic test example 2", t => { | ||
t.ok( true, "this test is fine" ); | ||
}); | ||
|
||
QUnit.module( "nested module b.1", () => { | ||
|
||
// This test will be prefixed with the following module label: | ||
// "module b > nested module b.1" | ||
test( "a basic test example 3", t => { | ||
t.ok( true, "this test is fine" ); | ||
}); | ||
}); | ||
}); | ||
``` | ||
|
||
--- | ||
|
||
A sample for using the before, beforeEach, afterEach, and after callbacks | ||
|
||
```js | ||
QUnit.module( "module A", { | ||
before: function() { | ||
// prepare something once for all tests | ||
}, | ||
beforeEach: function() { | ||
// prepare something before each test | ||
}, | ||
afterEach: function() { | ||
// clean up after each test | ||
}, | ||
after: function() { | ||
// clean up once after all tests are done | ||
} | ||
}); | ||
``` | ||
|
||
--- | ||
|
||
Hooks share the same context as their respective test | ||
|
||
```js | ||
QUnit.module( "Machine Maker", { | ||
beforeEach: function() { | ||
this.maker = new Maker(); | ||
this.parts = [ "wheels", "motor", "chassis" ]; | ||
} | ||
}); | ||
|
||
QUnit.test( "makes a robot", function( assert ) { | ||
this.parts.push( "arduino" ); | ||
assert.equal( this.maker.build( this.parts ), "robot" ); | ||
assert.deepEqual( this.maker.made, [ "robot" ] ); | ||
}); | ||
|
||
QUnit.test( "makes a car", function( assert ) { | ||
assert.equal( this.maker.build( this.parts ), "car" ); | ||
this.maker.duplicate(); | ||
assert.deepEqual( this.maker.made, [ "car", "car" ] ); | ||
}); | ||
``` | ||
|
||
--- | ||
|
||
Hooks stack on nested modules | ||
|
||
```js | ||
QUnit.module( "grouped tests argument hooks", function( hooks ) { | ||
hooks.beforeEach( function( assert ) { | ||
assert.ok( true, "beforeEach called" ); | ||
} ); | ||
|
||
hooks.afterEach( function( assert ) { | ||
assert.ok( true, "afterEach called" ); | ||
} ); | ||
|
||
QUnit.test( "call hooks", function( assert ) { | ||
assert.expect( 2 ); | ||
} ); | ||
|
||
QUnit.module( "stacked hooks", function( hooks ) { | ||
|
||
// This will run after the parent module's beforeEach hook | ||
hooks.beforeEach( function( assert ) { | ||
assert.ok( true, "nested beforeEach called" ); | ||
} ); | ||
|
||
// This will run before the parent module's afterEach | ||
hooks.afterEach( function( assert ) { | ||
assert.ok( true, "nested afterEach called" ); | ||
} ); | ||
|
||
QUnit.test( "call hooks", function( assert ) { | ||
assert.expect( 4 ); | ||
} ); | ||
} ); | ||
} ); | ||
``` | ||
|
||
--- | ||
|
||
An example of handling an asynchronous `then`able Promise result in hooks. This example uses an [ES6 Promise][] interface that is fulfilled after connecting to or disconnecting from database. | ||
|
||
[ES6 Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise | ||
|
||
```js | ||
QUnit.module( "Database connection", { | ||
before: function() { | ||
return new Promise( function( resolve, reject ) { | ||
DB.connect( function( err ) { | ||
if ( err ) { | ||
reject( err ); | ||
} else { | ||
resolve(); | ||
} | ||
} ); | ||
} ); | ||
}, | ||
after: function() { | ||
return new Promise( function( resolve, reject ) { | ||
DB.disconnect( function( err ) { | ||
if ( err ) { | ||
reject( err ); | ||
} else { | ||
resolve(); | ||
} | ||
} ); | ||
} ); | ||
} | ||
} ); | ||
``` |
Oops, something went wrong.