SlideShare a Scribd company logo
1 of 18
UNIT TESTING USING JASMINE
JAVASCRIPT
IMPORTANCE OF UNIT TEST
 Makes the process Agile
 Improves the Quality of Code
 Finds application issues/bugs early
 Detect Changes that may break the design contract in refactoring
 Provide debugging process
 Provides documentation
 Reduces cost
AVAILABLE UNIT TEST FRAMEWORKS
Find more unit test frameworks - https://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript
WHY JASMINE FRAMEWORK
 Behaviour driven development framework, also supports TDD
 Used for synchronous and asynchronous javascript code
 Does not rely on DOM or any browser
 Has built in assertion library and command line utility to run the tests
 Has simple syntax 
HELLO WORLD EXAMPLE
Javascript function –
- return ‘Hello World’ String
Unit test case for Javascript function –
- Calls actual function and matches the
output with expected output
INSTALL JASMINE FRAMEWORK
 Download latest version of Jasmine framework – click here
 Extract all the files
 Open ‘SpecRunner.html’ file
JASMINE FILE STRUCTURE
Boot Js –
this file "boots" Jasmine,
performing all of the
necessary initialization
before executing the
loaded environment and
all of a project's specs.
Spec folder -
Contains the Javascript
tesintg files unit test
files
Src folder -
Contains the Javascript
source files
Jasmine-html.js –
Javascript library which
has pure js functions to
capture the running
statistics of suits / specs
Jasmine.js –
Jasmine’s core engine
which responsible to
manage test life cycle
SpecRunner.html–
Test case runner HTML
file
CREATE TEST AND TEST SUITE
 describe(string suiteName) - Declare test suites using this function
 Group of all respective it() /test cases
 it (string testName) – Declare test case
 Write multiple it() calls in a single describe() function
 The string you passed to the describe() as the first parameter will be concatenated with the string passed to the
it(), to describe the complete name of the spec.
Syntax :
describe(‘Suite Name – Scenario name’, function() {
it(‘test case 1 name’, function() {
...
};
it(‘test case 2 name’, function() {
...
};
})
MATCHERS
• Any matcher can evaluate to a negative
assertion by chaining the call to expect with
a not before calling the matcher
• Each matcher implements a boolean
comparison between the actual value and
the expected value.
• It is responsible for reporting to Jasmine if
the expectation is true or false. Jasmine will
then pass or fail the spec.
LIST OF MATCHERS
SETUP AND TEARDOWN METHODS
 beforeEach() and afterEach() – runs before and after for every suite
 beforeAll() and afterAll() – runs before and after all the suites
before All afterAll
beforeEach
Test
afterEach
Test Suits
TEARDOWN METHODS EXAMPLE
beforeEach and afterEach Example beforeAll and afterAll Example
EXAMPLE - MATH.JS
• Create new file in SRC Folder
• Set file name as ‘Math.js’
• Create these functions for addition,
subtraction
• Make an entry in specRunner.html file
EXAMPLE - MATH-SPEC.JS
• Create new file in ‘spec’ Folder
• Set file name as ‘Math-spec.js’
• Make an entry in SpecRunner.html
file
JASMINE SPEC-RUNNER DASHBOARD
• Open SpecRunner.html file in any browser
• Calculator is the name of the ‘Test suite’
• Name start with ‘should’ are the spec /scenario
description
FAILING SPEC
 The fail () function causes a spec to fail.
 It can take a failure message or an Error object as a parameter.
FAILING SPEC RESULTS
THANK YOU

More Related Content

What's hot

Refactoring: Improving the design of existing code. Chapter 6.
Refactoring: Improving the design of existing code. Chapter 6.Refactoring: Improving the design of existing code. Chapter 6.
Refactoring: Improving the design of existing code. Chapter 6.Andrés Callejas González
 
Unit Testing with Python
Unit Testing with PythonUnit Testing with Python
Unit Testing with PythonMicroPyramid .
 
Unit testing using Munit Part 1
Unit testing using Munit Part 1Unit testing using Munit Part 1
Unit testing using Munit Part 1Anand kalla
 
Unit testing Ch. 13 of Programming Ruby
Unit testing Ch. 13 of Programming RubyUnit testing Ch. 13 of Programming Ruby
Unit testing Ch. 13 of Programming Rubylvrubygroup
 
Wix Automation - Test State Pattern - 11.9.16
Wix Automation - Test State Pattern - 11.9.16Wix Automation - Test State Pattern - 11.9.16
Wix Automation - Test State Pattern - 11.9.16Efrat Attas
 
Part 11 sql model clause-return all rows
Part 11 sql model clause-return all rowsPart 11 sql model clause-return all rows
Part 11 sql model clause-return all rowsGirija Muscut
 
Unit Testing in WordPress
Unit Testing in WordPressUnit Testing in WordPress
Unit Testing in WordPressBarry Kooij
 
Unit testing.pptx [repaired]
Unit testing.pptx [repaired]Unit testing.pptx [repaired]
Unit testing.pptx [repaired]Mohammad Asmar
 
Intro To Unit and integration Testing
Intro To Unit and integration TestingIntro To Unit and integration Testing
Intro To Unit and integration TestingPaul Churchward
 
JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101Hazem Saleh
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warOleksiy Rezchykov
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaEdureka!
 

What's hot (20)

Refactoring: Improving the design of existing code. Chapter 6.
Refactoring: Improving the design of existing code. Chapter 6.Refactoring: Improving the design of existing code. Chapter 6.
Refactoring: Improving the design of existing code. Chapter 6.
 
Unit Testing with Python
Unit Testing with PythonUnit Testing with Python
Unit Testing with Python
 
Unit testing using Munit Part 1
Unit testing using Munit Part 1Unit testing using Munit Part 1
Unit testing using Munit Part 1
 
Unit testing Ch. 13 of Programming Ruby
Unit testing Ch. 13 of Programming RubyUnit testing Ch. 13 of Programming Ruby
Unit testing Ch. 13 of Programming Ruby
 
TestNG vs Junit
TestNG vs JunitTestNG vs Junit
TestNG vs Junit
 
Action filter
Action filterAction filter
Action filter
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 
Wix Automation - Test State Pattern - 11.9.16
Wix Automation - Test State Pattern - 11.9.16Wix Automation - Test State Pattern - 11.9.16
Wix Automation - Test State Pattern - 11.9.16
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Intro to junit
Intro to junitIntro to junit
Intro to junit
 
Var arg methods
Var arg methodsVar arg methods
Var arg methods
 
Part 11 sql model clause-return all rows
Part 11 sql model clause-return all rowsPart 11 sql model clause-return all rows
Part 11 sql model clause-return all rows
 
Unit test
Unit testUnit test
Unit test
 
Unit Testing in WordPress
Unit Testing in WordPressUnit Testing in WordPress
Unit Testing in WordPress
 
Unit testing.pptx [repaired]
Unit testing.pptx [repaired]Unit testing.pptx [repaired]
Unit testing.pptx [repaired]
 
Intro To Unit and integration Testing
Intro To Unit and integration TestingIntro To Unit and integration Testing
Intro To Unit and integration Testing
 
JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the war
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
 
Unit testing
Unit testingUnit testing
Unit testing
 

Similar to Unit testing using jasmine in Javascript

An Introduction to AngularJs Unittesting
An Introduction to AngularJs UnittestingAn Introduction to AngularJs Unittesting
An Introduction to AngularJs UnittestingInthra onsap
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineGil Fink
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSKnoldus Inc.
 
In search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testingIn search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testingAnna Khabibullina
 
S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringromanovfedor
 
Testing akka-actors
Testing akka-actorsTesting akka-actors
Testing akka-actorsKnoldus Inc.
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSam Brannen
 
Testing And Mxunit In ColdFusion
Testing And Mxunit In ColdFusionTesting And Mxunit In ColdFusion
Testing And Mxunit In ColdFusionDenard Springle IV
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingVisual Engineering
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnitvaruntaliyan
 
Appium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation ExecutionAppium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation ExecutionpCloudy
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciollaAndrea Paciolla
 

Similar to Unit testing using jasmine in Javascript (20)

jasmine
jasminejasmine
jasmine
 
Jasmine framework
Jasmine frameworkJasmine framework
Jasmine framework
 
An Introduction to AngularJs Unittesting
An Introduction to AngularJs UnittestingAn Introduction to AngularJs Unittesting
An Introduction to AngularJs Unittesting
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
 
In search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testingIn search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testing
 
Mxunit
MxunitMxunit
Mxunit
 
S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discovering
 
Testing akka-actors
Testing akka-actorsTesting akka-actors
Testing akka-actors
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing Support
 
Junit_.pptx
Junit_.pptxJunit_.pptx
Junit_.pptx
 
Testing And Mxunit In ColdFusion
Testing And Mxunit In ColdFusionTesting And Mxunit In ColdFusion
Testing And Mxunit In ColdFusion
 
Unit testing
Unit testingUnit testing
Unit testing
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Testing Ansible
Testing AnsibleTesting Ansible
Testing Ansible
 
Appium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation ExecutionAppium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation Execution
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
 

Recently uploaded

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 

Recently uploaded (20)

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 

Unit testing using jasmine in Javascript

  • 1. UNIT TESTING USING JASMINE JAVASCRIPT
  • 2. IMPORTANCE OF UNIT TEST  Makes the process Agile  Improves the Quality of Code  Finds application issues/bugs early  Detect Changes that may break the design contract in refactoring  Provide debugging process  Provides documentation  Reduces cost
  • 3. AVAILABLE UNIT TEST FRAMEWORKS Find more unit test frameworks - https://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript
  • 4. WHY JASMINE FRAMEWORK  Behaviour driven development framework, also supports TDD  Used for synchronous and asynchronous javascript code  Does not rely on DOM or any browser  Has built in assertion library and command line utility to run the tests  Has simple syntax 
  • 5. HELLO WORLD EXAMPLE Javascript function – - return ‘Hello World’ String Unit test case for Javascript function – - Calls actual function and matches the output with expected output
  • 6. INSTALL JASMINE FRAMEWORK  Download latest version of Jasmine framework – click here  Extract all the files  Open ‘SpecRunner.html’ file
  • 7. JASMINE FILE STRUCTURE Boot Js – this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. Spec folder - Contains the Javascript tesintg files unit test files Src folder - Contains the Javascript source files Jasmine-html.js – Javascript library which has pure js functions to capture the running statistics of suits / specs Jasmine.js – Jasmine’s core engine which responsible to manage test life cycle SpecRunner.html– Test case runner HTML file
  • 8. CREATE TEST AND TEST SUITE  describe(string suiteName) - Declare test suites using this function  Group of all respective it() /test cases  it (string testName) – Declare test case  Write multiple it() calls in a single describe() function  The string you passed to the describe() as the first parameter will be concatenated with the string passed to the it(), to describe the complete name of the spec. Syntax : describe(‘Suite Name – Scenario name’, function() { it(‘test case 1 name’, function() { ... }; it(‘test case 2 name’, function() { ... }; })
  • 9. MATCHERS • Any matcher can evaluate to a negative assertion by chaining the call to expect with a not before calling the matcher • Each matcher implements a boolean comparison between the actual value and the expected value. • It is responsible for reporting to Jasmine if the expectation is true or false. Jasmine will then pass or fail the spec.
  • 11. SETUP AND TEARDOWN METHODS  beforeEach() and afterEach() – runs before and after for every suite  beforeAll() and afterAll() – runs before and after all the suites before All afterAll beforeEach Test afterEach Test Suits
  • 12. TEARDOWN METHODS EXAMPLE beforeEach and afterEach Example beforeAll and afterAll Example
  • 13. EXAMPLE - MATH.JS • Create new file in SRC Folder • Set file name as ‘Math.js’ • Create these functions for addition, subtraction • Make an entry in specRunner.html file
  • 14. EXAMPLE - MATH-SPEC.JS • Create new file in ‘spec’ Folder • Set file name as ‘Math-spec.js’ • Make an entry in SpecRunner.html file
  • 15. JASMINE SPEC-RUNNER DASHBOARD • Open SpecRunner.html file in any browser • Calculator is the name of the ‘Test suite’ • Name start with ‘should’ are the spec /scenario description
  • 16. FAILING SPEC  The fail () function causes a spec to fail.  It can take a failure message or an Error object as a parameter.