Skip to content

Commit

Permalink
tests: comply to the new rules
Browse files Browse the repository at this point in the history
Use `assert.strictEqual`/`assert.true`/`assert.false`
  • Loading branch information
XhmikosR committed Sep 15, 2021
1 parent 5391ecd commit 551f37a
Show file tree
Hide file tree
Showing 12 changed files with 468 additions and 459 deletions.
10 changes: 5 additions & 5 deletions js/tests/unit/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $(function () {
assert.expect(2)
var $el = $('<div/>')
var $alert = $el.bootstrapAlert()
assert.ok($alert instanceof $, 'returns jquery collection')
assert.true($alert instanceof $, 'returns jquery collection')
assert.strictEqual($alert[0], $el[0], 'collection contains element')
})

Expand All @@ -44,7 +44,7 @@ $(function () {

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

assert.strictEqual($alert.hasClass('show'), false, 'remove .show class on .close click')
assert.false($alert.hasClass('show'), 'remove .show class on .close click')
})

QUnit.test('should remove element when clicking .close', function (assert) {
Expand Down Expand Up @@ -104,18 +104,18 @@ $(function () {
var $el = $('<div/>')
var $alert = $el.bootstrapAlert()

assert.ok(typeof $alert.data('bs.alert') !== 'undefined')
assert.notStrictEqual(typeof $alert.data('bs.alert'), 'undefined')

$alert.data('bs.alert').dispose()

assert.ok(typeof $alert.data('bs.button') === 'undefined')
assert.strictEqual(typeof $alert.data('bs.button'), 'undefined')
})

QUnit.test('should return alert version', function (assert) {
assert.expect(1)

if (typeof Alert !== 'undefined') {
assert.ok(typeof Alert.VERSION === 'string')
assert.strictEqual(typeof Alert.VERSION, 'string')
} else {
assert.notOk()
}
Expand Down
126 changes: 63 additions & 63 deletions js/tests/unit/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ $(function () {
assert.expect(2)
var $el = $('<div/>')
var $button = $el.bootstrapButton()
assert.ok($button instanceof $, 'returns jquery collection')
assert.true($button instanceof $, 'returns jquery collection')
assert.strictEqual($button[0], $el[0], 'collection contains element')
})

QUnit.test('should toggle active', function (assert) {
assert.expect(2)
var $btn = $('<button class="btn" data-toggle="button">mdo</button>')
assert.ok(!$btn.hasClass('active'), 'btn does not have active class')
assert.false($btn.hasClass('active'), 'btn does not have active class')
$btn.bootstrapButton('toggle')
assert.ok($btn.hasClass('active'), 'btn has class active')
assert.true($btn.hasClass('active'), 'btn has class active')
})

QUnit.test('should toggle active when btn children are clicked', function (assert) {
Expand All @@ -48,9 +48,9 @@ $(function () {
$btn
.append($inner)
.appendTo('#qunit-fixture')
assert.ok(!$btn.hasClass('active'), 'btn does not have active class')
assert.false($btn.hasClass('active'), 'btn does not have active class')
$inner.trigger('click')
assert.ok($btn.hasClass('active'), 'btn has class active')
assert.true($btn.hasClass('active'), 'btn has class active')
})

QUnit.test('should toggle aria-pressed', function (assert) {
Expand Down Expand Up @@ -107,7 +107,7 @@ $(function () {
$btn.appendTo('#qunit-fixture')
$(window).trigger($.Event('load'))
setTimeout(function () {
assert.ok($btn.hasClass('active'), 'button with aria-pressed="true" has been given class active')
assert.true($btn.hasClass('active'), 'button with aria-pressed="true" has been given class active')
done()
}, 5)
})
Expand All @@ -125,7 +125,7 @@ $(function () {

$(window).trigger($.Event('load'))
setTimeout(function () {
assert.ok($btn.hasClass('active'), 'checked checkbox button has been given class active')
assert.true($btn.hasClass('active'), 'checked checkbox button has been given class active')
done()
}, 5)
})
Expand All @@ -137,7 +137,7 @@ $(function () {
$btn.appendTo('#qunit-fixture')
$(window).trigger($.Event('load'))
setTimeout(function () {
assert.ok(!$btn.hasClass('active'), 'button without aria-pressed="true" has had active class removed')
assert.false($btn.hasClass('active'), 'button without aria-pressed="true" has had active class removed')
done()
}, 5)
})
Expand All @@ -155,7 +155,7 @@ $(function () {

$(window).trigger($.Event('load'))
setTimeout(function () {
assert.ok(!$btn.hasClass('active'), 'unchecked checkbox button has had active class removed')
assert.false($btn.hasClass('active'), 'unchecked checkbox button has had active class removed')
done()
}, 5)
})
Expand Down Expand Up @@ -199,7 +199,7 @@ $(function () {
})

setTimeout(function () {
assert.ok(countChangeEvent === 1, 'onchange event fired only once')
assert.strictEqual(countChangeEvent, 1, 'onchange event fired only once')
done()
}, 5)

Expand All @@ -224,28 +224,28 @@ $(function () {
var $btn1 = $group.children().eq(0)
var $btn2 = $group.children().eq(1)

assert.ok($btn1.hasClass('active'), 'btn1 has active class')
assert.ok($btn1.find('input').prop('checked'), 'btn1 is checked')
assert.ok(!$btn2.hasClass('active'), 'btn2 does not have active class')
assert.ok(!$btn2.find('input').prop('checked'), 'btn2 is not checked')
assert.true($btn1.hasClass('active'), 'btn1 has active class')
assert.true($btn1.find('input').prop('checked'), 'btn1 is checked')
assert.false($btn2.hasClass('active'), 'btn2 does not have active class')
assert.false($btn2.find('input').prop('checked'), 'btn2 is not checked')
$btn2.find('input').trigger('click')
assert.ok(!$btn1.hasClass('active'), 'btn1 does not have active class')
assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is not checked')
assert.ok($btn2.hasClass('active'), 'btn2 has active class')
assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked')
assert.false($btn1.hasClass('active'), 'btn1 does not have active class')
assert.false($btn1.find('input').prop('checked'), 'btn1 is not checked')
assert.true($btn2.hasClass('active'), 'btn2 has active class')
assert.true($btn2.find('input').prop('checked'), 'btn2 is checked')

$btn2.find('input').trigger('click') // Clicking an already checked radio should not un-check it
assert.ok(!$btn1.hasClass('active'), 'btn1 does not have active class')
assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is not checked')
assert.ok($btn2.hasClass('active'), 'btn2 has active class')
assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked')
assert.false($btn1.hasClass('active'), 'btn1 does not have active class')
assert.false($btn1.find('input').prop('checked'), 'btn1 is not checked')
assert.true($btn2.hasClass('active'), 'btn2 has active class')
assert.true($btn2.find('input').prop('checked'), 'btn2 is checked')
$btn1.bootstrapButton('toggle')
assert.ok($btn1.hasClass('active'), 'btn1 has active class')
assert.ok($btn1.find('input').prop('checked'), 'btn1 prop is checked')
assert.ok($btn1.find('input')[0].checked, 'btn1 is checked with jquery')
assert.ok(!$btn2.hasClass('active'), 'btn2 does not have active class')
assert.ok(!$btn2.find('input').prop('checked'), 'btn2 is not checked')
assert.ok(!$btn2.find('input')[0].checked, 'btn2 is not checked')
assert.true($btn1.hasClass('active'), 'btn1 has active class')
assert.true($btn1.find('input').prop('checked'), 'btn1 prop is checked')
assert.true($btn1.find('input')[0].checked, 'btn1 is checked with jquery')
assert.false($btn2.hasClass('active'), 'btn2 does not have active class')
assert.false($btn2.find('input').prop('checked'), 'btn2 is not checked')
assert.false($btn2.find('input')[0].checked, 'btn2 is not checked')
})

QUnit.test('should fire click event on input', function (assert) {
Expand Down Expand Up @@ -300,10 +300,10 @@ $(function () {
var $btn2 = $group.children().eq(1)

$btn1.find('input').trigger('click')
assert.ok($btn1.is(':not([aria-pressed])'), 'label for nested checkbox input has not been given an aria-pressed attribute')
assert.true($btn1.is(':not([aria-pressed])'), 'label for nested checkbox input has not been given an aria-pressed attribute')

$btn2.find('input').trigger('click')
assert.ok($btn2.is(':not([aria-pressed])'), 'label for nested radio input has not been given an aria-pressed attribute')
assert.true($btn2.is(':not([aria-pressed])'), 'label for nested radio input has not been given an aria-pressed attribute')
})

QUnit.test('should handle disabled attribute on non-button elements', function (assert) {
Expand All @@ -318,11 +318,11 @@ $(function () {
var $btn = $group.children().eq(0)
var $input = $btn.children().eq(0)

assert.ok($btn.is(':not(.active)'), 'button is initially not active')
assert.ok(!$input.prop('checked'), 'checkbox is initially not checked')
assert.true($btn.is(':not(.active)'), 'button is initially not active')
assert.false($input.prop('checked'), 'checkbox is initially not checked')
$btn[0].click() // fire a real click on the DOM node itself, not a click() on the jQuery object that just aliases to trigger('click')
assert.ok($btn.is(':not(.active)'), 'button did not become active')
assert.ok(!$input.prop('checked'), 'checkbox did not get checked')
assert.true($btn.is(':not(.active)'), 'button did not become active')
assert.false($input.prop('checked'), 'checkbox did not get checked')
})

QUnit.test('should not set active class if inner hidden checkbox is disabled but author forgot to set disabled class on outer button', function (assert) {
Expand All @@ -337,11 +337,11 @@ $(function () {
var $btn = $group.children().eq(0)
var $input = $btn.children().eq(0)

assert.ok($btn.is(':not(.active)'), 'button is initially not active')
assert.ok(!$input.prop('checked'), 'checkbox is initially not checked')
assert.true($btn.is(':not(.active)'), 'button is initially not active')
assert.false($input.prop('checked'), 'checkbox is initially not checked')
$btn[0].click() // fire a real click on the DOM node itself, not a click() on the jQuery object that just aliases to trigger('click')
assert.ok($btn.is(':not(.active)'), 'button did not become active')
assert.ok(!$input.prop('checked'), 'checkbox did not get checked')
assert.true($btn.is(':not(.active)'), 'button did not become active')
assert.false($input.prop('checked'), 'checkbox did not get checked')
})

QUnit.test('should correctly set checked state on input and active class on label when using <label><input></label> structure', function (assert) {
Expand All @@ -356,11 +356,11 @@ $(function () {
var $label = $group.children().eq(0)
var $input = $label.children().eq(0)

assert.ok($label.is(':not(.active)'), 'label is initially not active')
assert.ok(!$input.prop('checked'), 'checkbox is initially not checked')
assert.true($label.is(':not(.active)'), 'label is initially not active')
assert.false($input.prop('checked'), 'checkbox is initially not checked')
$label[0].click() // fire a real click on the DOM node itself, not a click() on the jQuery object that just aliases to trigger('click')
assert.ok($label.is('.active'), 'label is active after click')
assert.ok($input.prop('checked'), 'checkbox is checked after click')
assert.true($label.is('.active'), 'label is active after click')
assert.true($input.prop('checked'), 'checkbox is checked after click')
})

QUnit.test('should correctly set checked state on input and active class on the faked button when using <div><input></div> structure', function (assert) {
Expand All @@ -375,11 +375,11 @@ $(function () {
var $btn = $group.children().eq(0)
var $input = $btn.children().eq(0)

assert.ok($btn.is(':not(.active)'), '<div> is initially not active')
assert.ok(!$input.prop('checked'), 'checkbox is initially not checked')
assert.true($btn.is(':not(.active)'), '<div> is initially not active')
assert.false($input.prop('checked'), 'checkbox is initially not checked')
$btn[0].click() // fire a real click on the DOM node itself, not a click() on the jQuery object that just aliases to trigger('click')
assert.ok($btn.is('.active'), '<div> is active after click')
assert.ok($input.prop('checked'), 'checkbox is checked after click')
assert.true($btn.is('.active'), '<div> is active after click')
assert.true($input.prop('checked'), 'checkbox is checked after click')
})

QUnit.test('should correctly set checked state on input and active class on the label when using button toggle', function (assert) {
Expand All @@ -394,13 +394,13 @@ $(function () {
var $btn = $group.children().eq(0)
var $input = $btn.children().eq(0)

assert.ok($btn.is(':not(.active)'), '<label> is initially not active')
assert.ok(!$input.prop('checked'), 'checkbox property is initially not checked')
assert.ok(!$input[0].checked, 'checkbox is not checked by jquery after click')
assert.true($btn.is(':not(.active)'), '<label> is initially not active')
assert.false($input.prop('checked'), 'checkbox property is initially not checked')
assert.false($input[0].checked, 'checkbox is not checked by jquery after click')
$btn.bootstrapButton('toggle')
assert.ok($btn.is('.active'), '<label> is active after click')
assert.ok($input.prop('checked'), 'checkbox property is checked after click')
assert.ok($input[0].checked, 'checkbox is checked by jquery after click')
assert.true($btn.is('.active'), '<label> is active after click')
assert.true($input.prop('checked'), 'checkbox property is checked after click')
assert.true($input[0].checked, 'checkbox is checked by jquery after click')
})

QUnit.test('should not do anything if the click was just sent to the outer container with data-toggle', function (assert) {
Expand All @@ -415,11 +415,11 @@ $(function () {
var $label = $group.children().eq(0)
var $input = $label.children().eq(0)

assert.ok($label.is(':not(.active)'), 'label is initially not active')
assert.ok(!$input.prop('checked'), 'checkbox is initially not checked')
assert.true($label.is(':not(.active)'), 'label is initially not active')
assert.false($input.prop('checked'), 'checkbox is initially not checked')
$group[0].click() // fire a real click on the DOM node itself, not a click() on the jQuery object that just aliases to trigger('click')
assert.ok($label.is(':not(.active)'), 'label is not active after click')
assert.ok(!$input.prop('checked'), 'checkbox is not checked after click')
assert.true($label.is(':not(.active)'), 'label is not active after click')
assert.false($input.prop('checked'), 'checkbox is not checked after click')
})

QUnit.test('should not try and set checked property on an input of type="hidden"', function (assert) {
Expand All @@ -434,9 +434,9 @@ $(function () {
var $label = $group.children().eq(0)
var $input = $label.children().eq(0)

assert.ok(!$input.prop('checked'), 'hidden input initially has no checked property')
assert.false($input.prop('checked'), 'hidden input initially has no checked property')
$label[0].click() // fire a real click on the DOM node itself, not a click() on the jQuery object that just aliases to trigger('click')
assert.ok(!$input.prop('checked'), 'hidden input does not have a checked property')
assert.false($input.prop('checked'), 'hidden input does not have a checked property')
})

QUnit.test('should not try and set checked property on an input that is not a radio button or checkbox', function (assert) {
Expand All @@ -451,9 +451,9 @@ $(function () {
var $label = $group.children().eq(0)
var $input = $label.children().eq(0)

assert.ok(!$input.prop('checked'), 'text input initially has no checked property')
assert.false($input.prop('checked'), 'text input initially has no checked property')
$label[0].click() // fire a real click on the DOM node itself, not a click() on the jQuery object that just aliases to trigger('click')
assert.ok(!$input.prop('checked'), 'text input does not have a checked property')
assert.false($input.prop('checked'), 'text input does not have a checked property')
})

QUnit.test('dispose should remove data and the element', function (assert) {
Expand All @@ -462,18 +462,18 @@ $(function () {
var $el = $('<div/>')
var $button = $el.bootstrapButton()

assert.ok(typeof $button.data('bs.button') !== 'undefined')
assert.notStrictEqual(typeof $button.data('bs.button'), 'undefined')

$button.data('bs.button').dispose()

assert.ok(typeof $button.data('bs.button') === 'undefined')
assert.strictEqual(typeof $button.data('bs.button'), 'undefined')
})

QUnit.test('should return button version', function (assert) {
assert.expect(1)

if (typeof Button !== 'undefined') {
assert.ok(typeof Button.VERSION === 'string')
assert.strictEqual(typeof Button.VERSION, 'string')
} else {
assert.notOk()
}
Expand Down
Loading

0 comments on commit 551f37a

Please sign in to comment.