|
@@ -7,7 +7,7 @@ describe('Bootstrap Switch:', function () {
|
|
|
$.fx.off = true
|
|
|
})
|
|
|
afterEach(function () {
|
|
|
- return $('.' + $.fn.bootstrapSwitch.defaults.baseClass).bootstrapSwitch('destroy')
|
|
|
+ return $(`.${$.fn.bootstrapSwitch.defaults.baseClass}`).destroy()
|
|
|
})
|
|
|
|
|
|
function createCheckbox () {
|
|
@@ -30,31 +30,23 @@ describe('Bootstrap Switch:', function () {
|
|
|
}
|
|
|
|
|
|
it('should set the default options as element options, except state', function () {
|
|
|
- var $switch
|
|
|
- $switch = createCheckbox().prop('checked', true).bootstrapSwitch()
|
|
|
+ const $switch = createCheckbox().prop('checked', true).bootstrapSwitch()
|
|
|
expect(getOptions($switch)).toEqual($.fn.bootstrapSwitch.defaults)
|
|
|
})
|
|
|
|
|
|
it('should override default options with initialization ones', function () {
|
|
|
- var $switch, $switch2
|
|
|
- $switch = createCheckbox().prop('checked', false).bootstrapSwitch()
|
|
|
- $switch2 = createCheckbox().bootstrapSwitch({
|
|
|
- state: false
|
|
|
- })
|
|
|
+ const $switch = createCheckbox().prop('checked', false).bootstrapSwitch()
|
|
|
+ const $switch2 = createCheckbox().bootstrapSwitch({ state: false })
|
|
|
expect(getOptions($switch).state).toBe(false)
|
|
|
expect(getOptions($switch2).state).toBe(false)
|
|
|
})
|
|
|
|
|
|
it('should something', function () {
|
|
|
- var $switch, eventDoc, eventElement
|
|
|
- eventDoc = eventElement = 0
|
|
|
- $switch = createCheckbox().bootstrapSwitch()
|
|
|
- $(document).on('switchChange.bootstrapSwitch', ':checkbox', function (event, state) {
|
|
|
- return eventDoc++
|
|
|
- })
|
|
|
- $(':checkbox').on('switchChange.bootstrapSwitch', function (event, state) {
|
|
|
- return eventElement++
|
|
|
- })
|
|
|
+ const $switch = createCheckbox().bootstrapSwitch()
|
|
|
+ let eventDoc = 0
|
|
|
+ let eventElement = 0
|
|
|
+ $(document).on('switchChange.bootstrapSwitch', ':checkbox', function (event, state) { eventDoc++ })
|
|
|
+ $(':checkbox').on('switchChange.bootstrapSwitch', function (event, state) { eventElement++ })
|
|
|
$switch.click()
|
|
|
expect(eventElement).toEqual(eventDoc)
|
|
|
expect(eventElement).toEqual(1)
|
|
@@ -62,14 +54,13 @@ describe('Bootstrap Switch:', function () {
|
|
|
|
|
|
describe('The Checkbox Bootstrap Switch', function () {
|
|
|
it('should conserve its state if onSwitchChange returns false', function () {
|
|
|
- var $indeterminateSwitch, $switch
|
|
|
- $switch = createCheckbox().bootstrapSwitch({
|
|
|
+ const $switch = createCheckbox().bootstrapSwitch({
|
|
|
onSwitchChange: function (e, s) {
|
|
|
expect(s).toEqual(true)
|
|
|
return false
|
|
|
}
|
|
|
})
|
|
|
- $indeterminateSwitch = createCheckbox().data('indeterminate', true).bootstrapSwitch({
|
|
|
+ const $indeterminateSwitch = createCheckbox().data('indeterminate', true).bootstrapSwitch({
|
|
|
onSwitchChange: function (e, s) {
|
|
|
expect(s).toEqual(true)
|
|
|
return false
|
|
@@ -82,8 +73,7 @@ describe('Bootstrap Switch:', function () {
|
|
|
})
|
|
|
|
|
|
it('should change its state if onSwitchChange not returns false', function () {
|
|
|
- var $switch
|
|
|
- $switch = createCheckbox().bootstrapSwitch({
|
|
|
+ const $switch = createCheckbox().bootstrapSwitch({
|
|
|
onSwitchChange: function (e, s) {
|
|
|
expect(s).toEqual(true)
|
|
|
}
|
|
@@ -95,10 +85,9 @@ describe('Bootstrap Switch:', function () {
|
|
|
|
|
|
describe('The Radio Bootstrap Switch', function () {
|
|
|
it('should conserve its state if onSwitchChange returns false', function () {
|
|
|
- var $radio1, $radio2, $radio3
|
|
|
- $radio1 = createRadio().prop('checked', true)
|
|
|
- $radio2 = createRadio().prop('checked', false)
|
|
|
- $radio3 = createRadio().prop('checked', false)
|
|
|
+ const $radio1 = createRadio().prop('checked', true)
|
|
|
+ const $radio2 = createRadio().prop('checked', false)
|
|
|
+ const $radio3 = createRadio().prop('checked', false)
|
|
|
$('[name="name"]').bootstrapSwitch({
|
|
|
onSwitchChange: function (e, s) {
|
|
|
expect(s).toEqual(true)
|
|
@@ -112,10 +101,9 @@ describe('Bootstrap Switch:', function () {
|
|
|
})
|
|
|
|
|
|
it('should change its state if onSwitchChange not returns false', function () {
|
|
|
- var $radio1, $radio2, $radio3
|
|
|
- $radio1 = createRadio().prop('checked', true)
|
|
|
- $radio2 = createRadio().prop('checked', false)
|
|
|
- $radio3 = createRadio().prop('checked', false)
|
|
|
+ const $radio1 = createRadio().prop('checked', true)
|
|
|
+ const $radio2 = createRadio().prop('checked', false)
|
|
|
+ const $radio3 = createRadio().prop('checked', false)
|
|
|
$('[name="name"]').bootstrapSwitch({
|
|
|
onSwitchChange: function (e, s) {
|
|
|
expect(s).toEqual(true)
|