Modularise and test setting of jQuery Mobile config options.

This commit is contained in:
jcass 2016-04-03 16:06:25 +02:00
parent e2920920ed
commit 1345357a5e
3 changed files with 54 additions and 7 deletions

View File

@ -1,8 +1,25 @@
// jQuery Mobile configuration options
// see: http://api.jquerymobile.com/1.3/global-config/
$(document).bind('mobileinit', function () {
$.extend($.mobile, {
ajaxEnabled: false,
hashListeningEnabled: false
})
})
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory)
} else if (typeof module === 'object' && module.exports) {
module.exports = factory()
} else {
root.configureJQueryMobile = factory()
}
}(this, function () {
'use strict'
function configureJQueryMobile () {
$.extend($.mobile, {
ajaxEnabled: false,
hashListeningEnabled: false
})
}
$(document).bind('mobileinit', configureJQueryMobile)
return configureJQueryMobile
}))

View File

@ -1,6 +1,6 @@
CACHE MANIFEST
# 2016-04-03:v1
# 2016-04-03:v2
NETWORK:
*

View File

@ -0,0 +1,30 @@
var chai = require('chai')
var expect = chai.expect
var assert = chai.assert
chai.use(require('chai-string'))
chai.use(require('chai-jquery'))
var sinon = require('sinon')
var configureJQueryMobile = require('../../mopidy_musicbox_webclient/static/js/custom_scripting.js')
describe('jQuery Defaults', function () {
it('should disable ajax and hashListening', function () {
expect($.mobile.ajaxEnabled).to.be.true
expect($.mobile.hashListeningEnabled).to.be.true
configureJQueryMobile()
expect($.mobile.ajaxEnabled).to.be.false
expect($.mobile.hashListeningEnabled).to.be.false
})
it('should bind to "mobileinit"', function () {
var configSpy = sinon.spy(configureJQueryMobile)
$(document).bind('mobileinit', configSpy)
expect(configSpy.called).to.be.false
$(document).trigger('mobileinit')
expect(configSpy.called).to.be.true
configSpy.reset()
})
})