From 80379c56c16f5ce9d7e071b9c3bfb77a77a8d52d Mon Sep 17 00:00:00 2001 From: Johann-S Date: Fri, 9 Mar 2018 23:17:57 +0100 Subject: [PATCH] Add Sinon to do better unit test --- js/tests/README.md | 14 +- js/tests/index.html | 3 + js/tests/karma.conf.js | 3 +- js/tests/unit/.eslintrc.json | 1 + js/tests/vendor/sinon.min.js | 1 + package-lock.json | 1421 ++++++++-------------------------- package.json | 5 +- 7 files changed, 323 insertions(+), 1125 deletions(-) create mode 100644 js/tests/vendor/sinon.min.js diff --git a/js/tests/README.md b/js/tests/README.md index 23c5ff39df54..3f033e1dc4ea 100644 --- a/js/tests/README.md +++ b/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/.js`. +Bootstrap uses [QUnit](https://qunitjs.com/) and [Sinon](http://sinonjs.org/). Each plugin has a file dedicated to its tests in `unit/.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() - $('
') - .appendTo('#qunit-fixture') + var $tooltip = $('
').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') diff --git a/js/tests/index.html b/js/tests/index.html index 471fa36aa742..e5a76d98ea3f 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -25,6 +25,9 @@ + + +