Skip to content

Commit

Permalink
Add Sinon to do better unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Mar 12, 2018
1 parent 836de9c commit 80379c5
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 1,125 deletions.
14 changes: 9 additions & 5 deletions js/tests/README.md
@@ -1,9 +1,9 @@
## How does Bootstrap's test suite work?

Bootstrap uses [QUnit](https://qunitjs.com/), a powerful, easy-to-use JavaScript unit test framework. Each plugin has a file dedicated to its tests in `unit/<plugin-name>.js`.
Bootstrap uses [QUnit](https://qunitjs.com/) and [Sinon](http://sinonjs.org/). Each plugin has a file dedicated to its tests in `unit/<plugin-name>.js`.

* `unit/` contains the unit test files for each Bootstrap plugin.
* `vendor/` contains third-party testing-related code (QUnit and jQuery).
* `vendor/` contains third-party testing-related code (QUnit, jQuery and Sinon).
* `visual/` contains "visual" tests which are run interactively in real browsers and require manual verification by humans.

To run the unit test suite via [Karma](http://karma-runner.github.io/), run `npm run js-test`.
Expand Down Expand Up @@ -51,13 +51,17 @@ QUnit.test('should describe the unit being tested', function (assert) {

// Asynchronous test
QUnit.test('should describe the unit being tested', function (assert) {
assert.expect(1)
assert.expect(2)
var done = assert.async()

$('<div title="tooltip title"></div>')
.appendTo('#qunit-fixture')
var $tooltip = $('<div title="tooltip title"></div>').bootstrapTooltip()
var tooltipInstance = $tooltip.data('bs.tooltip')
var spyShow = sinon.spy(tooltipInstance, 'show')

$tooltip.appendTo('#qunit-fixture')
.on('shown.bs.tooltip', function () {
assert.ok(true, '"shown" event was fired after calling "show"')
assert.ok(spyShow.called, 'show called')
done()
})
.bootstrapTooltip('show')
Expand Down
3 changes: 3 additions & 0 deletions js/tests/index.html
Expand Up @@ -25,6 +25,9 @@
<link rel="stylesheet" href="vendor/qunit.css" media="screen">
<script src="vendor/qunit.js"></script>

<!-- Sinon -->
<script src="vendor/sinon.min.js"></script>

<script>
// Disable jQuery event aliases to ensure we don't accidentally use any of them
[
Expand Down
3 changes: 2 additions & 1 deletion js/tests/karma.conf.js
Expand Up @@ -8,11 +8,12 @@ module.exports = (config) => {

config.set({
basePath: '../..',
frameworks: ['qunit', 'detectBrowsers'],
frameworks: ['qunit', 'sinon', 'detectBrowsers'],
plugins: [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-qunit',
'karma-sinon',
'karma-detect-browsers',
'karma-coverage-istanbul-reporter'
],
Expand Down
1 change: 1 addition & 0 deletions js/tests/unit/.eslintrc.json
Expand Up @@ -5,6 +5,7 @@
"jquery": true
},
"globals": {
"sinon": false,
"Util": false
},
"parserOptions": {
Expand Down
1 change: 1 addition & 0 deletions js/tests/vendor/sinon.min.js

Large diffs are not rendered by default.

0 comments on commit 80379c5

Please sign in to comment.