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

PDF
Embedding JGit
PPTX
Byte code manipulation and instrumentalization in Java
DOCX
CV Nissa Mukharomah SE -
DOCX
Prison Tattoos
PPTX
Häufige Seretide Nebenwirkungen
PDF
PPTX
Top 8 college librarian resume samples
PPTX
5 Tips for Creating a Great Website Design | DMAC | Boca Raton, FL
Embedding JGit
Byte code manipulation and instrumentalization in Java
CV Nissa Mukharomah SE -
Prison Tattoos
Häufige Seretide Nebenwirkungen
Top 8 college librarian resume samples
5 Tips for Creating a Great Website Design | DMAC | Boca Raton, FL

Similar to JavaScript unit testing with Jasmine (20)

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

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