Skip to content

Instantly share code, notes, and snippets.

@steckel
Created March 14, 2012 04:59
Show Gist options
  • Save steckel/2034199 to your computer and use it in GitHub Desktop.
Save steckel/2034199 to your computer and use it in GitHub Desktop.
jQuery.plugin boilerplate spec (for use with Mocha and Should.js)
root = if window? then window else global
root.$ = require("jquery")
root.jQuery = $
root = if window? then window else global
unless window?
require("./support/faux-browser")
require("../jquery.plugin")
describe 'Chainable', ->
describe '$("div.element").pluginName()', ->
it 'should return $("div.element") so that other jQuery methods can be chained also called upon', ->
$jQueryElem = $("<div id='content'></div>")
$jQueryElem.pluginName().should.eql $jQueryElem
describe 'Plugin Options', ->
describe '$.fn.pluginName.options', ->
it 'should contain the default options', ->
$.fn.pluginName.defaults.should.be.eql
some: "options"
also: "others"
describe '$.fn.pluginName({some:"newOptions", also:"more"})', ->
it 'should overwrite the default options that are mentioned', ->
pluginObjectName = new root.PluginObjectName()
pluginObjectName.init
some: "newOptions"
also: "more"
pluginObjectName.options.should.be.eql
some: "newOptions"
also: "more"
describe '$.fn.pluginName({some:"newOptions"})', ->
it 'should overwrite the default options that are mentioned but, ignore ones that aren\'t', ->
pluginObjectName = new root.PluginObjectName()
pluginObjectName.init
some: "newOptions"
pluginObjectName.options.should.be.eql
some: "newOptions"
also: "others"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment