the sweet smell of jasmine for testing javascript
TRANSCRIPT
![Page 2: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/2.jpg)
Why test?
![Page 3: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/3.jpg)
How test?
ManualAutomated
![Page 4: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/4.jpg)
Using JavaScript
SupportAccessibility
![Page 5: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/5.jpg)
What is Jasmine?
![Page 6: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/6.jpg)
What is Behaviour Driven Development?
![Page 7: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/7.jpg)
What can you do with Jasmine?
SuitesSpecsMatchersSpies
![Page 8: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/8.jpg)
Jasmine Test
//Suitedescribe(’Spec name', function () { //Spec it(’what you are testing', function () {//arrange//act//assert expect(actualValue).matcher(); });});
![Page 9: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/9.jpg)
Matchers
toEqualtoThrowtoMatchtoContaintoBeTruthy/ tobeFalsytoBeLessThan/tobeGreaterThantoBeDefined/toBeUndefined
![Page 10: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/10.jpg)
SetUp and Teardown
beforeEach(function (){ //do what you need to;});
afterEach(function (){ //do what you need to;});
![Page 11: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/11.jpg)
SetUp and Teardown
beforeAll (function (){ //do what you need to;});
afterAll(function (){ //do what you need to;});
![Page 12: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/12.jpg)
Custom Matchers
beforeEach(function () { jasmine.addMatchers({
matcherName: function (util, customEqualityTesters)
return {Compare: function(actual, expected){ }}});});
![Page 13: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/13.jpg)
Spies
Spy on a methodspyOn(obj, ‘method’)
Verify its been calledExpect(obj.method).toHaveBeenCalled()
Verify its been calledExpect(obj.method).toHaveBeenCalledWith(‘x’,’y’)
![Page 14: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/14.jpg)
Spies continued……Fix the return value of the spyspyOn(obj, ‘method’).andReturn(‘Return me’)
How many times has it been called?Obj.method.callcount
What were the arguments to the last callObj.mthod.mostrecentCall.args
Reset calls made to the spy so farObject.method.reset()
![Page 15: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/15.jpg)
Spies continued……Obj.method =Jasmine.createSpy(“spy Name”);
jasmine.createSpy("spy Name ").andReturn(“Return Value");
jasmine.createSpy(" spy Name ").andCallFake(function() { do something; return “Return Value";});
![Page 16: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/16.jpg)
Get Jasmine
You can get the latest version of Jasmine from:-
https://github.com/jasmine/jasmine/releases
![Page 17: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/17.jpg)
Example Code
https://github.com/EmmaATester/JasmineDemo
![Page 18: The sweet smell of jasmine for testing JavaScript](https://reader036.vdocument.in/reader036/viewer/2022071722/55b9a739bb61ebcb228b46c5/html5/thumbnails/18.jpg)
The sweet smell of Jasmine when testing JavaScript
Emma [email protected]@towerswatson.com
Image: Jasmine by Ken Bosma