1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00

Add Sinon to do better unit test

This commit is contained in:
Johann-S 2018-03-09 23:17:57 +01:00
parent c98ece5490
commit 4d5c5923fa
7 changed files with 586 additions and 272 deletions

View file

@ -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`.
@ -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')

View file

@ -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
[

View file

@ -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'
],

View file

@ -5,6 +5,7 @@
"jquery": true
},
"globals": {
"sinon": false,
"Util": false
},
"parserOptions": {

1
js/tests/vendor/sinon.min.js vendored Normal file

File diff suppressed because one or more lines are too long

834
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -107,6 +107,7 @@
"karma-detect-browsers": "^2.2.6",
"karma-firefox-launcher": "^1.1.0",
"karma-qunit": "^1.2.1",
"karma-sinon": "^1.0.5",
"node-sass": "^4.7.2",
"nodemon": "^1.17.1",
"npm-run-all": "^4.1.2",
@ -118,6 +119,7 @@
"rollup-plugin-node-resolve": "^3.0.3",
"shelljs": "^0.8.1",
"shx": "^0.2.2",
"sinon": "^4.4.3",
"sri-toolbox": "^0.2.0",
"stylelint": "^9.1.1",
"stylelint-config-recommended-scss": "^3.1.0",