|
1 year ago | |
---|---|---|
.. | ||
helpers | 1 year ago | |
integration | 1 year ago | |
unit | 1 year ago | |
visual | 1 year ago | |
README.md | 1 year ago | |
browsers.js | 1 year ago | |
karma.conf.js | 1 year ago |
Bootstrap uses Jasmine. Each plugin has a file dedicated to its tests in tests/unit/<plugin-name>.spec.js
.
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, run npm run js-test
.
To run the unit test suite via Karma and debug, run npm run js-debug
.
tests/unit/<plugin-name>.spec.js
).npm run js-test
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.
describe
.expect
to ensure something is expected.Currently we're aiming for at least 90% test coverage for our code. To ensure your changes meet or exceed this limit, run npm run js-test-karma
and open the file in js/coverage/lcov-report/index.html
to see the code coverage for each plugin. See more details when you select a plugin and ensure your change is fully covered by unit tests.
// Synchronous test
describe('getInstance', () => {
it('should return null if there is no instance', () => {
// Make assertion
expect(Tab.getInstance(fixtureEl)).toEqual(null)
})
it('should return this instance', () => {
fixtureEl.innerHTML = '<div></div>'
const divEl = fixtureEl.querySelector('div')
const tab = new Tab(divEl)
// Make assertion
expect(Tab.getInstance(divEl)).toEqual(tab)
})
})
// Asynchronous test
it('should show a tooltip without the animation', done => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip"></a>'
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl, {
animation: false
})
tooltipEl.addEventListener('shown.bs.tooltip', () => {
const tip = document.querySelector('.tooltip')
expect(tip).not.toBeNull()
expect(tip.classList.contains('fade')).toEqual(false)
done()
})
tooltip.show()
})