twbs--bootstrap/js/tests
Mark Otto 58082cd83e Merge branch 'master' into v4
Conflicts:
	.gitignore
	Gruntfile.js
	_config.yml
	dist/css/bootstrap-theme.css
	dist/css/bootstrap-theme.min.css
	dist/css/bootstrap.css
	dist/css/bootstrap.css.map
	dist/css/bootstrap.min.css
	dist/js/bootstrap.js
	dist/js/bootstrap.min.js
	docs/_includes/components/navbar.html
	docs/_includes/components/progress-bars.html
	docs/_includes/css/grid.html
	docs/_includes/css/overview.html
	docs/_includes/customizer-variables.html
	docs/_includes/getting-started/accessibility.html
	docs/_includes/getting-started/browser-device-support.html
	docs/_includes/getting-started/community.html
	docs/_includes/getting-started/disabling-responsiveness.html
	docs/_includes/getting-started/download.html
	docs/_includes/getting-started/examples.html
	docs/_includes/getting-started/license.html
	docs/_includes/getting-started/third-party-support.html
	docs/_includes/js/alerts.html
	docs/_includes/js/buttons.html
	docs/_includes/js/carousel.html
	docs/_includes/js/collapse.html
	docs/_includes/js/dropdowns.html
	docs/_includes/js/modal.html
	docs/_includes/js/popovers.html
	docs/_includes/js/scrollspy.html
	docs/_includes/js/tabs.html
	docs/_includes/js/tooltips.html
	docs/_includes/js/transitions.html
	docs/_includes/nav/javascript.html
	docs/_includes/nav/main.html
	docs/about.html
	docs/assets/css/docs.min.css
	docs/assets/css/src/docs.css
	docs/assets/js/customize.min.js
	docs/assets/js/raw-files.min.js
	docs/assets/js/src/customizer.js
	docs/dist/css/bootstrap-theme.css
	docs/dist/css/bootstrap-theme.min.css
	docs/dist/css/bootstrap.css
	docs/dist/css/bootstrap.css.map
	docs/dist/css/bootstrap.min.css
	docs/dist/js/bootstrap.js
	docs/dist/js/bootstrap.min.js
	docs/migration.html
	js/affix.js
	js/alert.js
	js/button.js
	js/carousel.js
	js/collapse.js
	js/dropdown.js
	js/modal.js
	js/popover.js
	js/scrollspy.js
	js/tab.js
	js/tests/unit/affix.js
	js/tests/unit/button.js
	js/tests/unit/carousel.js
	js/tests/unit/modal.js
	js/tests/unit/tooltip.js
	js/tests/visual/modal.html
	js/tooltip.js
	less/component-animations.less
	less/jumbotron.less
	less/mixins/background-variant.less
	less/mixins/buttons.less
	less/mixins/responsive-visibility.less
	less/mixins/text-emphasis.less
	less/navbar.less
	less/navs.less
	less/scaffolding.less
	less/tooltip.less
	less/utilities.less
	less/variables.less
	package.json
	scss/_buttons.scss
	scss/_forms.scss
	scss/_modal.scss
2015-03-29 00:08:54 -07:00
..
unit Merge branch 'master' into v4 2015-03-29 00:08:54 -07:00
vendor
visual Merge branch 'master' into v4 2015-03-29 00:08:54 -07:00
README.md
closure.html
index.html Merge branch 'master' into v4 2015-03-29 00:08:54 -07:00

README.md

How does Bootstrap's test suite work?

Bootstrap uses QUnit, a powerful, easy-to-use JavaScript unit test framework. 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).
  • visual/ contains "visual" tests which are run interactively in real browsers and require manual verification by humans.

To run the unit test suite via PhantomJS, run grunt test-js.

To run the unit test suite via a real web browser, open index.html in the browser.

How do I add a new unit test?

  1. Locate and open the file dedicated to the plugin which you need to add tests to (unit/<plugin-name>.js).
  2. Review the QUnit API Documentation and use the existing tests as references for how to structure your new tests.
  3. Write the necessary unit test(s) for the new or revised functionality.
  4. Run grunt test-js to see the results of your newly-added test(s).

Note: Your new unit tests should fail before your changes are applied to the plugin, and should pass after your changes are applied to the plugin.

What should a unit test look like?

  • Each test should have a unique name clearly stating what unit is being tested.
  • Each test should test only one unit per test, although one test can include several assertions. Create multiple tests for multiple units of functionality.
  • Each test should begin with assert.expect to ensure that the expected assertions are run.
  • Each test should follow the project's JavaScript Code Guidelines

Example tests

// Synchronous test
QUnit.test('should describe the unit being tested', function (assert) {
  assert.expect(1)
  var templateHTML = '<div class="alert alert-danger fade in">'
      + '<a class="close" href="#" data-dismiss="alert">×</a>'
      + '<p><strong>Template necessary for the test.</p>'
      + '</div>'
  var $alert = $(templateHTML).appendTo('#qunit-fixture').bootstrapAlert()

  $alert.find('.close').click()

  // Make assertion
  assert.strictEqual($alert.hasClass('in'), false, 'remove .in class on .close click')
})

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

  $('<div title="tooltip title"></div>')
    .appendTo('#qunit-fixture')
    .on('shown.bs.tooltip', function () {
      assert.ok(true, '"shown" event was fired after calling "show"')
      done()
    })
    .bootstrapTooltip('show')
})