16

Click here to load reader

jQuery plugin & testing with Jasmine

Embed Size (px)

Citation preview

Page 1: jQuery plugin & testing with Jasmine

jQuery Plugins & JasmineA lightning quick example

@mparramon

Page 2: jQuery plugin & testing with Jasmine

What?With

· some useful js code

Create

· a full-fledged jQuery

plugin

· with unit testing

In 5 minutes!

Page 3: jQuery plugin & testing with Jasmine

File inputs in some browsers:

The problem

Page 4: jQuery plugin & testing with Jasmine

let's fix it!

· add styling

· custom button

· initial value

Based on quirksmode.org/dom/inputfile.html

Page 5: jQuery plugin & testing with Jasmine

jQuery plugin

http://docs.jquery.com/Plugins/Authoring

Page 6: jQuery plugin & testing with Jasmine

Basic Framework

Page 7: jQuery plugin & testing with Jasmine

Defaults and options

Page 8: jQuery plugin & testing with Jasmine

Mantaining chainability

Page 9: jQuery plugin & testing with Jasmine

Unit testing with Jasmine

http://pivotal.github.com/jasmine/

Page 10: jQuery plugin & testing with Jasmine

Initial setupModify SpecRunner.html:

Page 11: jQuery plugin & testing with Jasmine

DSL

Page 12: jQuery plugin & testing with Jasmine

jasmine-jquery2 extensions for Jasmine:

· an HTML fixtures API· a set of jQuery custom matchers

https://github.com/velesin/jasmine-jquery

Page 13: jQuery plugin & testing with Jasmine

Fixtures

Page 14: jQuery plugin & testing with Jasmine

Expectations

Page 15: jQuery plugin & testing with Jasmine

Our final codejquery-enhancedfileinput

↳ lib

↳ jasmine-1.3.0

spec

↳ jquery-enhancedfileinput_spec.js

↳ jasmine-jquery-1.3.1.js

src

↳ jquery-enhancedfileinput.js

↳ demo.html

↳ README.md

↳ SpecRunner.html