SlideShare a Scribd company logo
JavaScript unit
testing with
Jasmine
Yuval Dagai
Agenda
• Jasmine Overview
• Folder structure
• Conventions
• Jasmine plugins
• Test code cases
o RequireJs configuration
o Mock considerations
o Mock Ajax
o Mock JayData (datajs)
• Example of code failure discovery
• Selenium runner
Jasmine Overview
• http://pivotal.github.io/jasmine/
• Suite = describe
• Spec = it
• Expect and matchers
• beforeEach, afterEach
• Spies
• Async operations
• SpecRunner
• Test results
Folder structure
• The tests root folder is under “WWW” folder.
• Spec runners HTML files are in the root of the tests
folder.
• Folders:
o lib – hold Jasmine source files.
o specs – holds all specs.
• cafe
• login
• pb
o mocks – hold all mock objects
• modules – hold all mock modules that corresponds to source
modules.
• responses – hold mock responses objects.
• objects – hold any other mock object.
o helpers – hold any helper objects.
Conventions
• Spec runner html files are in the root of the tests
folder
• Spec file name = <module>.spec.js
• Responses file name = <module>.responses.js
• Mock module name same as source module name
• Use the require map id “src” for mock files with
source dependencies. see
“testmockspbmodulesdb.j”
Jasmine plugins
• jasmine-html
• jasmine-jquery
• mock-ajax
Test code cases
• RequireJs configuration
• Mock considerations
• Mock Ajax
• Mock JayData (datajs)
Example of code failure
discovery
• Missing reject case for loading deferred object in
plans.js
Selenium runner
• Selenium can run the jasmine unit tests in build.
End

More Related Content

Similar to JavaScript unit testing with Jasmine

SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius Valatka
Vasil Remeniuk
 
Introduction tomaven
Introduction tomavenIntroduction tomaven
Introduction tomaven
Manav Prasad
 
DanNotes 2013: OpenNTF Domino API
DanNotes 2013: OpenNTF Domino APIDanNotes 2013: OpenNTF Domino API
DanNotes 2013: OpenNTF Domino API
Paul Withers
 
How Class Data Sharing Can Speed up Your Jakarta EE Application Startup
How Class Data Sharing Can Speed up Your Jakarta EE Application StartupHow Class Data Sharing Can Speed up Your Jakarta EE Application Startup
How Class Data Sharing Can Speed up Your Jakarta EE Application Startup
Rudy De Busscher
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
Mindfire Solutions
 
Ceylon module repositories by Aleš Justin
Ceylon module repositories by Aleš JustinCeylon module repositories by Aleš Justin
Ceylon module repositories by Aleš Justin
UnFroMage
 
Hibernate Performance Tuning @JUG Thüringen
Hibernate Performance Tuning @JUG ThüringenHibernate Performance Tuning @JUG Thüringen
Hibernate Performance Tuning @JUG Thüringen
Thorben Janssen
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
Ryan Cuprak
 
Bccon use notes objects in memory and other useful
Bccon   use notes objects in memory and other usefulBccon   use notes objects in memory and other useful
Bccon use notes objects in memory and other useful
Frank van der Linden
 
Alfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy BehavioursAlfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy Behaviours
J V
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Brett Meyer
 
RIBBUN SOFTWARE
RIBBUN SOFTWARERIBBUN SOFTWARE
RIBBUN SOFTWARE
mosewoodward24
 
Java01
Java01Java01
Introduction what is java
Introduction what is javaIntroduction what is java
Introduction what is java
sanjeeviniindia1186
 
Java01
Java01Java01
Java01
Java01Java01
Java01
Java01Java01
Java01
Prakash Mani
 
Java >= 9
Java >= 9Java >= 9
Java >= 9
Benjamin Pack
 
Introduction to Monsoon PHP framework
Introduction to Monsoon PHP frameworkIntroduction to Monsoon PHP framework
Introduction to Monsoon PHP framework
Krishna Srikanth Manda
 
How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.
Fazreil Amreen Abdul Jalil
 

Similar to JavaScript unit testing with Jasmine (20)

SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius Valatka
 
Introduction tomaven
Introduction tomavenIntroduction tomaven
Introduction tomaven
 
DanNotes 2013: OpenNTF Domino API
DanNotes 2013: OpenNTF Domino APIDanNotes 2013: OpenNTF Domino API
DanNotes 2013: OpenNTF Domino API
 
How Class Data Sharing Can Speed up Your Jakarta EE Application Startup
How Class Data Sharing Can Speed up Your Jakarta EE Application StartupHow Class Data Sharing Can Speed up Your Jakarta EE Application Startup
How Class Data Sharing Can Speed up Your Jakarta EE Application Startup
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Ceylon module repositories by Aleš Justin
Ceylon module repositories by Aleš JustinCeylon module repositories by Aleš Justin
Ceylon module repositories by Aleš Justin
 
Hibernate Performance Tuning @JUG Thüringen
Hibernate Performance Tuning @JUG ThüringenHibernate Performance Tuning @JUG Thüringen
Hibernate Performance Tuning @JUG Thüringen
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
 
Bccon use notes objects in memory and other useful
Bccon   use notes objects in memory and other usefulBccon   use notes objects in memory and other useful
Bccon use notes objects in memory and other useful
 
Alfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy BehavioursAlfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy Behaviours
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
 
RIBBUN SOFTWARE
RIBBUN SOFTWARERIBBUN SOFTWARE
RIBBUN SOFTWARE
 
Java01
Java01Java01
Java01
 
Introduction what is java
Introduction what is javaIntroduction what is java
Introduction what is java
 
Java01
Java01Java01
Java01
 
Java01
Java01Java01
Java01
 
Java01
Java01Java01
Java01
 
Java >= 9
Java >= 9Java >= 9
Java >= 9
 
Introduction to Monsoon PHP framework
Introduction to Monsoon PHP frameworkIntroduction to Monsoon PHP framework
Introduction to Monsoon PHP framework
 
How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.
 

JavaScript unit testing with Jasmine

  • 2. Agenda • Jasmine Overview • Folder structure • Conventions • Jasmine plugins • Test code cases o RequireJs configuration o Mock considerations o Mock Ajax o Mock JayData (datajs) • Example of code failure discovery • Selenium runner
  • 3. Jasmine Overview • http://pivotal.github.io/jasmine/ • Suite = describe • Spec = it • Expect and matchers • beforeEach, afterEach • Spies • Async operations • SpecRunner • Test results
  • 4. Folder structure • The tests root folder is under “WWW” folder. • Spec runners HTML files are in the root of the tests folder. • Folders: o lib – hold Jasmine source files. o specs – holds all specs. • cafe • login • pb o mocks – hold all mock objects • modules – hold all mock modules that corresponds to source modules. • responses – hold mock responses objects. • objects – hold any other mock object. o helpers – hold any helper objects.
  • 5. Conventions • Spec runner html files are in the root of the tests folder • Spec file name = <module>.spec.js • Responses file name = <module>.responses.js • Mock module name same as source module name • Use the require map id “src” for mock files with source dependencies. see “testmockspbmodulesdb.j”
  • 6. Jasmine plugins • jasmine-html • jasmine-jquery • mock-ajax
  • 7. Test code cases • RequireJs configuration • Mock considerations • Mock Ajax • Mock JayData (datajs)
  • 8. Example of code failure discovery • Missing reject case for loading deferred object in plans.js
  • 9. Selenium runner • Selenium can run the jasmine unit tests in build.
  • 10. End