Skip to content

Commit

Permalink
Merge pull request #16011 from twbs/fix-15315
Browse files Browse the repository at this point in the history
.collapse('hide') on hidden uninit-ed collapsible no longer shows it
  • Loading branch information
cvrebert committed Mar 9, 2015
2 parents 2c56b0f + 5c8d56d commit 21d5637
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion js/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
var data = $this.data('bs.collapse')
var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option)

if (!data && options.toggle && option == 'show') options.toggle = false
if (!data && options.toggle && /show|hide/.test(option)) options.toggle = false
if (!data) $this.data('bs.collapse', (data = new Collapse(this, options)))
if (typeof option == 'string') data[option]()
})
Expand Down
35 changes: 31 additions & 4 deletions js/tests/unit/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ $(function () {
})

QUnit.test('should hide a collapsed element', function (assert) {
assert.expect(2)
assert.expect(1)
var $el = $('<div class="collapse"/>').bootstrapCollapse('hide')

assert.ok(!$el.hasClass('in'), 'does not have class "in"')
assert.ok(/height/i.test($el.attr('style')), 'has height set')
})

QUnit.test('should not fire shown when show is prevented', function (assert) {
Expand Down Expand Up @@ -147,7 +146,7 @@ $(function () {
$target.click()
})

QUnit.test('should not close a collapse when initialized with "show" if already shown', function (assert) {
QUnit.test('should not close a collapse when initialized with "show" option if already shown', function (assert) {
assert.expect(0)
var done = assert.async()

Expand All @@ -162,7 +161,7 @@ $(function () {
setTimeout(done, 0)
})

QUnit.test('should open a collapse when initialized with "show" if not already shown', function (assert) {
QUnit.test('should open a collapse when initialized with "show" option if not already shown', function (assert) {
assert.expect(1)
var done = assert.async()

Expand All @@ -177,6 +176,34 @@ $(function () {
setTimeout(done, 0)
})

QUnit.test('should not show a collapse when initialized with "hide" option if already hidden', function (assert) {
assert.expect(0)
var done = assert.async()

$('<div class="collapse"></div>')
.appendTo('#qunit-fixture')
.on('show.bs.collapse', function () {
assert.ok(false, 'showing a previously-uninitialized hidden collapse when the "hide" method is called')
})
.bootstrapCollapse('hide')

setTimeout(done, 0)
})

QUnit.test('should hide a collapse when initialized with "hide" option if not already hidden', function (assert) {
assert.expect(1)
var done = assert.async()

$('<div class="collapse in"></div>')
.appendTo('#qunit-fixture')
.on('hide.bs.collapse', function () {
assert.ok(true, 'hiding a previously-uninitialized shown collapse when the "hide" method is called')
})
.bootstrapCollapse('hide')

setTimeout(done, 0)
})

QUnit.test('should remove "collapsed" class from active accordion target', function (assert) {
assert.expect(3)
var done = assert.async()
Expand Down

0 comments on commit 21d5637

Please sign in to comment.