Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Jasmine JavaScript Testing - Second Edition
Jasmine JavaScript Testing - Second Edition
Jasmine JavaScript Testing - Second Edition
Ebook280 pages2 hours

Jasmine JavaScript Testing - Second Edition

Rating: 0 out of 5 stars

()

Read preview

About this ebook

About This Book
  • Leverage the power of unit testing React.js to develop full-fledged JavaScript applications
  • Learn the best practices of modularization and code organization while scaling your application
  • Enhance your practical skills required to develop applications using the Jasmine framework in a step-by-step manner
Who This Book Is For

This book is for web developers and designers who work with React.js and JavaScript and who are new to unit testing and automation. It's assumed that you have a basic knowledge of JavaScript and HTML.

LanguageEnglish
Release dateApr 24, 2015
ISBN9781785283208
Jasmine JavaScript Testing - Second Edition

Related to Jasmine JavaScript Testing - Second Edition

Related ebooks

Internet & Web For You

View More

Related articles

Reviews for Jasmine JavaScript Testing - Second Edition

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Jasmine JavaScript Testing - Second Edition - Paulo Ragonha

    Table of Contents

    Jasmine JavaScript Testing Second Edition

    Credits

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    Why subscribe?

    Free access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Errata

    Piracy

    Questions

    1. Getting Started with Jasmine

    JavaScript – the bad parts

    Jasmine and behavior-driven development

    Downloading Jasmine

    Summary

    2. Your First Spec

    The Investment Tracker application

    Jasmine basics and thinking in BDD

    Setup and teardown

    Nested describes

    Setup and teardown

    Coding a spec with shared behavior

    Understanding matchers

    Custom matchers

    Built-in matchers

    The toEqual built-in matcher

    The toBe built-in matcher

    The toBeTruthy and toBeFalsy matchers

    The toBeUndefined, toBeNull, and toBeNaN built-in matchers

    The toBeDefined built-in matcher

    The toContain built-in matcher

    The toMatch built-in matcher

    The toBeLessThan and toBeGreaterThan built-in matchers

    The toBeCloseTo built-in matcher

    The toThrow built-in matcher

    Summary

    3. Testing Frontend Code

    Thinking in terms of components (Views)

    The module pattern

    Using HTML fixtures

    Basic View coding rules

    The View should encapsulate a DOM element

    Integrating Views with observers

    Testing Views with jQuery matchers

    The toBeMatchedBy jQuery matcher

    The toContainHtml jQuery matcher

    The toContainElement jQuery matcher

    The toHaveValue jQuery matcher

    The toHaveAttr jQuery matcher

    The toBeFocused jQuery matcher

    The toBeDisabled jQuery matcher

    More matchers

    Summary

    4. Asynchronous Testing – AJAX

    Acceptance criterion

    Setting up the scenario

    Installing Node.js

    Coding the server

    Running the server

    Writing the spec

    Asynchronous setups and teardowns

    Asynchronous specs

    Timeout

    Summary

    5. Jasmine Spies

    The bare spy

    Spying on an object's functions

    Testing DOM events

    Summary

    6. Light Speed Unit Testing

    Jasmine stubs

    Jasmine Ajax

    Installing the plugin

    A fake XMLHttpRequest

    Summary

    7. Testing React Applications

    Project setup

    Our first React component

    The Virtual DOM

    JSX

    Using JSX with Jasmine

    Component attributes (props)

    Component events

    Component state

    Component life cycle

    Composing components

    Summary

    8. Build Automation

    Module bundler – webpack

    Module definition

    Webpack project setup

    Managing dependencies with NPM

    Webpack configuration

    The spec runner

    Testing a module

    Test runner: Karma

    Quick feedback loop

    Watch and run the tests

    Watch and update the browser

    Optimizing for production

    Static code analysis: JSHint

    Continuous integration – Travis-CI

    Adding a project to Travis-CI

    Project setup

    Summary

    Index

    Jasmine JavaScript Testing Second Edition


    Jasmine JavaScript Testing Second Edition

    Copyright © 2015 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: August 2013

    Second edition: April 2015

    Production reference: 1210415

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-78528-204-1

    www.packtpub.com

    Credits

    Author

    Paulo Ragonha

    Reviewers

    Hany A. Elemary

    Ryzhikov Maksim

    Veer Shubhranshu Shrivastav

    Sergey Simonchik

    Commissioning Editor

    Amarabha Banerjee

    Acquisition Editor

    Larissa Pinto

    Content Development Editor

    Manasi Pandire

    Technical Editor

    Anushree Arun Tendulkar

    Copy Editor

    Sarang Chari

    Project Coordinator

    Suzanne Coutinho

    Proofreaders

    Paul Hindle

    Linda Morris

    Indexer

    Tejal Soni

    Production Coordinator

    Aparna Bhagat

    Cover Work

    Aparna Bhagat

    About the Author

    Paulo Ragonha is a software engineer with over 7 years of professional experience. An advocate of the open Web, he is inspired and driven to build compelling experiences on top of this ubiquitous platform.

    He loves to hack, so you will often see him wandering around in conferences or attending hackathons. His most recent professional experiences ranged from DevOps (with Chef and Docker) to moving up the stack with Node.js, Ruby, and Python and all the way toward building single-page applications (mostly with Backbone.js and ad hoc solutions).

    Passionate about automation, he sees testing as a liberating tool to enjoy the craft of writing code even more. Back in 2013, he wrote the first edition of the book Jasmine JavaScript Testing, Packt Publishing.

    Paulo has an amazing wife, who he loves very much. He lives in beautiful Florianópolis, a coastal city in the south of Brazil. He is a casual speaker, a biker, a runner, and a hobbyist photographer.

    About the Reviewers

    Hany A. Elemary is a software engineer / technical team lead at OCLC in Columbus, Ohio, currently working on the next generation of mobile/web apps (http://www.worldcat.org and WorldCat for local institutions). He has been blessed with diverse experience while working for multiple companies (from small software shops to large corporations) and seeing different releasable software strategies. He has a clear focus and passion for mobile/web UI design, interactions, usability, and accessibility. When there is time, he enjoys playing his acoustic guitar, AnnaMaria.

    Special thanks to my close friends and family for always pushing me to be better in every aspect of life.

    Ryzhikov Maksim is a 27-year-old software developer from Saint Petersburg, Russia.

    He develops complex web applications. He graduated from the physics faculty at Saint Petersburg State University. His journey into the world of software development started not so long ago—5 years ago.

    His brother invited him to join the team that developed programs for American hospitals, as an HTML developer.

    Ryzhikov started with developing a simple, static site for hospitals and then studied JavaScript, Ruby, and SQL and worked as a full-stack developer. In 5 years of work in the area of IT, he has worked in various projects and teams. He developed medical systems, dating sites, web mail (Yandex.Mail), and now he helps develop tools for developers at JetBrains.

    Veer Shubhranshu Shrivastav is an Indian software developer working with Tata Consultancy Services since 2013 and is a former research intern at IIIT-Delhi. He has worked on different technologies, such as PHP, Moodle, jQuery, AngularJS, RequireJS, Android, Jasmine, Ionic, and so on, and also takes an interest in cryptography, network security, and database technologies. He has worked with various Indian IT start-ups, helping them as a software architect.

    With his interest in the open source community, he developed a Pro*C library named CODBC, which is available at http://codbc.com. The library enables an object-oriented approach to connect C++ and Oracle Database.

    Sergey Simonchik is a software developer living and working in Saint Petersburg, Russia. He is lucky because he has a wonderful wife and a kind cat. Sergey develops the WebStorm IDE at JetBrains. He is working on improving JavaScript unit testing support and other IDE features.

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    For support files and downloads related to your book, please visit www.PacktPub.com.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    https://www2.packtpub.com/books/subscription/packtlib

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

    Why subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print, and bookmark content

    On demand and accessible via a web browser

    Free access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

    Preface

    This book is about being a better JavaScript developer. So, throughout the chapters, you will not only learn about writing tests in the Jasmine 'idiom', but also about the best practices in writing software in the JavaScript language. It is about acknowledging JavaScript as a real platform for application development and leveraging

    Enjoying the preview?
    Page 1 of 1