mirror of https://github.com/twbs/bootstrap.git
				
				
				
			Add Sinon to do better unit test
This commit is contained in:
		
							parent
							
								
									c98ece5490
								
							
						
					
					
						commit
						4d5c5923fa
					
				| 
						 | 
					@ -1,9 +1,9 @@
 | 
				
			||||||
## How does Bootstrap's test suite work?
 | 
					## 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.
 | 
					* `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.
 | 
					* `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`.
 | 
					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
 | 
					// Asynchronous test
 | 
				
			||||||
QUnit.test('should describe the unit being tested', function (assert) {
 | 
					QUnit.test('should describe the unit being tested', function (assert) {
 | 
				
			||||||
  assert.expect(1)
 | 
					  assert.expect(2)
 | 
				
			||||||
  var done = assert.async()
 | 
					  var done = assert.async()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $('<div title="tooltip title"></div>')
 | 
					  var $tooltip = $('<div title="tooltip title"></div>').bootstrapTooltip()
 | 
				
			||||||
    .appendTo('#qunit-fixture')
 | 
					  var tooltipInstance = $tooltip.data('bs.tooltip')
 | 
				
			||||||
 | 
					  var spyShow = sinon.spy(tooltipInstance, 'show')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $tooltip.appendTo('#qunit-fixture')
 | 
				
			||||||
    .on('shown.bs.tooltip', function () {
 | 
					    .on('shown.bs.tooltip', function () {
 | 
				
			||||||
      assert.ok(true, '"shown" event was fired after calling "show"')
 | 
					      assert.ok(true, '"shown" event was fired after calling "show"')
 | 
				
			||||||
 | 
					      assert.ok(spyShow.called, 'show called')
 | 
				
			||||||
      done()
 | 
					      done()
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    .bootstrapTooltip('show')
 | 
					    .bootstrapTooltip('show')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,6 +25,9 @@
 | 
				
			||||||
    <link rel="stylesheet" href="vendor/qunit.css" media="screen">
 | 
					    <link rel="stylesheet" href="vendor/qunit.css" media="screen">
 | 
				
			||||||
    <script src="vendor/qunit.js"></script>
 | 
					    <script src="vendor/qunit.js"></script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Sinon -->
 | 
				
			||||||
 | 
					    <script src="vendor/sinon.min.js"></script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <script>
 | 
					    <script>
 | 
				
			||||||
      // Disable jQuery event aliases to ensure we don't accidentally use any of them
 | 
					      // Disable jQuery event aliases to ensure we don't accidentally use any of them
 | 
				
			||||||
      [
 | 
					      [
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,11 +8,12 @@ module.exports = (config) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  config.set({
 | 
					  config.set({
 | 
				
			||||||
    basePath: '../..',
 | 
					    basePath: '../..',
 | 
				
			||||||
    frameworks: ['qunit', 'detectBrowsers'],
 | 
					    frameworks: ['qunit', 'sinon', 'detectBrowsers'],
 | 
				
			||||||
    plugins: [
 | 
					    plugins: [
 | 
				
			||||||
      'karma-chrome-launcher',
 | 
					      'karma-chrome-launcher',
 | 
				
			||||||
      'karma-firefox-launcher',
 | 
					      'karma-firefox-launcher',
 | 
				
			||||||
      'karma-qunit',
 | 
					      'karma-qunit',
 | 
				
			||||||
 | 
					      'karma-sinon',
 | 
				
			||||||
      'karma-detect-browsers',
 | 
					      'karma-detect-browsers',
 | 
				
			||||||
      'karma-coverage-istanbul-reporter'
 | 
					      'karma-coverage-istanbul-reporter'
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@
 | 
				
			||||||
    "jquery": true
 | 
					    "jquery": true
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "globals": {
 | 
					  "globals": {
 | 
				
			||||||
 | 
					    "sinon": false,
 | 
				
			||||||
    "Util": false
 | 
					    "Util": false
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "parserOptions": {
 | 
					  "parserOptions": {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
					@ -107,6 +107,7 @@
 | 
				
			||||||
    "karma-detect-browsers": "^2.2.6",
 | 
					    "karma-detect-browsers": "^2.2.6",
 | 
				
			||||||
    "karma-firefox-launcher": "^1.1.0",
 | 
					    "karma-firefox-launcher": "^1.1.0",
 | 
				
			||||||
    "karma-qunit": "^1.2.1",
 | 
					    "karma-qunit": "^1.2.1",
 | 
				
			||||||
 | 
					    "karma-sinon": "^1.0.5",
 | 
				
			||||||
    "node-sass": "^4.7.2",
 | 
					    "node-sass": "^4.7.2",
 | 
				
			||||||
    "nodemon": "^1.17.1",
 | 
					    "nodemon": "^1.17.1",
 | 
				
			||||||
    "npm-run-all": "^4.1.2",
 | 
					    "npm-run-all": "^4.1.2",
 | 
				
			||||||
| 
						 | 
					@ -118,6 +119,7 @@
 | 
				
			||||||
    "rollup-plugin-node-resolve": "^3.0.3",
 | 
					    "rollup-plugin-node-resolve": "^3.0.3",
 | 
				
			||||||
    "shelljs": "^0.8.1",
 | 
					    "shelljs": "^0.8.1",
 | 
				
			||||||
    "shx": "^0.2.2",
 | 
					    "shx": "^0.2.2",
 | 
				
			||||||
 | 
					    "sinon": "^4.4.3",
 | 
				
			||||||
    "sri-toolbox": "^0.2.0",
 | 
					    "sri-toolbox": "^0.2.0",
 | 
				
			||||||
    "stylelint": "^9.1.1",
 | 
					    "stylelint": "^9.1.1",
 | 
				
			||||||
    "stylelint-config-recommended-scss": "^3.1.0",
 | 
					    "stylelint-config-recommended-scss": "^3.1.0",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue