Your SlideShare is downloading. ×
Jasmine
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Jasmine

4,821

Published on

Lightning talk from FESuffolk

Lightning talk from FESuffolk

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
4,821
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Javascript issoftware too!(so where are the unit tests?) Kerry Buckley — @kerryb FESuffolk lightning talk 25 March 2013
  • 2. http://www.flickr.com/photos/saparevo/4948914064
  • 3. http://www.flickr.com/photos/igormazic/299854107
  • 4. UT No Yes ut/) No [107] (http://lbrtw.com/javascript-unit- Developed as a learning project test-framework-part-1) JSUnit Yes No Yes No [108] (http://www.jsunit.net/) JSUnit is no longer actively maintain Enhance JS Yes ed No Yes No [10 6] QUnit Port of Enhance PHP Yes Yes [109] (http://qunitjs.com/) jQuery test harness RhUnit [110] Yes Yes (http://www.iankent.co.uk/rhunit/) QUnit compatible Rhino/JUnit framew Crosscheck ork No Yes [10 7] J3Unit Browserless java-based framework Yes No [111] (http://j3unit.sourceforge.net/) Mocha No Yes [112] Yes Yes (http://visionmedia.github.com/moch JSNUnit a/) Yes No [10 8] YUI Test Yes Yes Yes Yes [10 9] JSSpec Yes No [11 0] UnitTesting Behaviour-driven development framew Yes ork No [11 1] script.aculo.us javascript test harness JSpec [113] Yes Yes Highly readable BDD, 50+ matchers (http://visionmedia.github.com/jspec) , DOM / framework independent, async, rhino, node.js support and mo re (no longer maintained) Jasmine [114] BDD, framework independent, easy Yes Yes integration with Ruby projects (http://pivotal.github.com/jasmine) and continuous builds. Allows for bot h DOM-less testing and screw-unit asynchronous testing. Yes No [11 2] Requires jQuery Test.Simple No[11 3] Yes Yes No [11 4] Write TAP-emitting unit tests in JavaSc ript and run them in your browser. Test.More No[1] Yes Yes No [11 5] Write TAP-emitting unit tests in JavaSc ript and run them in your TestCase browser. Yes No [11 6] TestIt Yes Yes [11 7] jsUnitTest Light-weight, non-polluting, and eas Yes y to set up and use Yes[11 8] JSTest Based on TestCase but without the Pro Yes totype dependency No [11 9] Light-weight, non-polluting browser-b JSTest.NET ased framework No Yes [115] (http://jstest.codeplex.com) Browserless JavaScript unit test runner for use with MsTest, XUnit, jsUnity Yes NUnit, etc. No Yes Yes [116] (http://jsunity.com/)RhinoUnit Context-agnostic (JavaScript, JScript No Yes [12 0] (ASP/WSH), Rhino, etc.) Rhino-based framework that allows testJasUnit s to be run in Ant Yes No Yes No [12 1] Light-weight framework. Part of a pro ject that provides Mocks and IoC.)FireUnit Yes No [117] (http://fireunit.org/) Testing framework that provides loggin g and viewing within a new tab of Firebug.Js-test-driver Yes Yes No [12 2] The goal of JsTestDriver is to build a JavaSc
  • 5. describe "2 + 2", -> it "is 4", -> expect(2 + 2).toEqual 4describe("2 + 2", function() { it("should be 4", function() { expect(2 + 2).toEqual(4); });});
  • 6. $ jasmine-headless-webkit -cRunning Jasmine specs....PASS: 1 test, 0 failures, 0.003 secs.Test ordering seed: --seed 2026
  • 7. encrypt = -> plainText = $("#plain-text").val() $.get "/encrypt", {text: plainText}, updateupdate = (data) -> $("#encrypted-text").val data.text$ -> $("#plain-text").keyup encrypt
  • 8. source "https://rubygems.org"...group :development, :test do ... gem "jasmine-headless-webkit" gem "jasmine-spec-extras"end
  • 9. src_files: - ["application.js"]helpers: - helpers/**/*spec_files: - "**/*[Ss]pec.*"src_dir:- app/assets/javascripts- vendor/assets/javascriptsspec_dir: spec/javascripts
  • 10. describe "Encryptor", -> beforeEach -> loadFixtures "encryptor.html" describe ".update", -> ...<input id="plain-text" /><input id="encrypted-text" />
  • 11. describe "Encryptor", -> beforeEach -> loadFixtures "encryptor.html" describe ".update", -> it "sets the #encrypted-text elements value to the supplied datas text attribute", -> update {text: "foo"} expect($("#encrypted-text").val()).toEqual "foo"
  • 12. Running Jasmine specs...FFAIL: 1 test, 1 failure, 0.003 secs.Encryptor .update sets the #encrypted-textelements value to the supplied datas textattribute. (...spec/javascripts/encryptor_spec.coffee:3) ReferenceError: Cant find variable: update
  • 13. // Generated by CoffeeScript 1.6.1(function() { var encrypt, update; encrypt = function() { var plainText; plainText = $("#plain-text").val(); return $.get("/encrypt", { text: plainText }, update); }; update = function(data) { return $("#encrypted-text").val(data.text); }; $(function() { return $("#plain-text").keyup(encrypt); });}).call(this);
  • 14. class Encryptor constructor: -> $("#plain-text").keyup @encrypt encrypt: => plainText = $("#plain-text").val() $.get "/encrypt", {text: plainText}, @update update: (data) => $("#encrypted-text").val data.text$ -> window.encryptor = new Encryptor
  • 15. describe ".encrypt", -> it "requests encryption of the #plain-text field, calling .update on success", -> $("#plain-text").val "foo" spyOn $, "get" window.encryptor.encrypt() expect($.get).toHaveBeenCalledWith "/encrypt", {text: "foo"}, window.encryptor.update
  • 16. someObject = {doSomething: ->}describe "an easy mistake to make", -> it "catches me out all the time", -> spyOn someObject, "doSomething" # Should fail – Im not calling doSomething expect(someObject.doSomething).toHaveBeenCalledRunning Jasmine specs....PASS: 1 test, 0 failures, 0.004 secs.Test ordering seed: --seed 7220
  • 17. Tuesday 2 April, 7pm The Brewery Tap

×