Instant Access to (Ebook) Jasmine JavaScript Testing, 2nd Edition: Test your JavaScript applications efficiently using Jasmine and React.js by Paulo Ragonha ISBN 9781785282041, 1785282042 ebook Full Chapters
Instant Access to (Ebook) Jasmine JavaScript Testing, 2nd Edition: Test your JavaScript applications efficiently using Jasmine and React.js by Paulo Ragonha ISBN 9781785282041, 1785282042 ebook Full Chapters
ebooknice.com
ebooknice.com
(Ebook) React.js Book: Learning React JavaScript Library
From Scratch by Greg Sidelnikov
https://ebooknice.com/product/react-js-book-learning-react-javascript-
library-from-scratch-7159540
ebooknice.com
ebooknice.com
www.it-ebooks.info
Jasmine JavaScript Testing
Second Edition
Paulo Ragonha
BIRMINGHAM - MUMBAI
www.it-ebooks.info
Jasmine JavaScript Testing
Second Edition
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.
ISBN 978-1-78528-204-1
www.packtpub.com
www.it-ebooks.info
Credits
Reviewers Proofreaders
Hany A. Elemary Paul Hindle
Ryzhikov Maksim Linda Morris
Veer Shubhranshu Shrivastav
Sergey Simonchik Indexer
Tejal Soni
Commissioning Editor
Amarabha Banerjee Production Coordinator
Aparna Bhagat
Acquisition Editor
Larissa Pinto Cover Work
Aparna Bhagat
Technical Editor
Anushree Arun Tendulkar
Copy Editor
Sarang Chari
www.it-ebooks.info
About the Author
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.
www.it-ebooks.info
About the Reviewers
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.
www.it-ebooks.info
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.
www.it-ebooks.info
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 [email protected] 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.
TM
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
www.it-ebooks.info
www.it-ebooks.info
Table of Contents
Preface v
Chapter 1: Getting Started with Jasmine 1
JavaScript – the bad parts 1
Jasmine and behavior-driven development 3
Downloading Jasmine 4
Summary 6
Chapter 2: Your First Spec 7
The Investment Tracker application 7
Jasmine basics and thinking in BDD 8
Setup and teardown 14
Nested describes 18
Setup and teardown 19
Coding a spec with shared behavior 19
Understanding matchers 20
Custom matchers 21
Built-in matchers 26
Summary 32
Chapter 3: Testing Frontend Code 33
Thinking in terms of components (Views) 34
The module pattern 35
Using HTML fixtures 36
Basic View coding rules 40
The View should encapsulate a DOM element 41
Integrating Views with observers 43
Testing Views with jQuery matchers 48
The toBeMatchedBy jQuery matcher 49
The toContainHtml jQuery matcher 50
The toContainElement jQuery matcher 50
[i]
www.it-ebooks.info
Table of Contents
www.it-ebooks.info
Table of Contents
[ iii ]
www.it-ebooks.info
www.it-ebooks.info
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 all its potential. It is also about tooling and automation and how to make
your life easier and more productive.
Most importantly, this book is about craftsmanship of not only working software,
but also well-crafted software.
Over the course of the chapters, the concept of test-driven development is explained
through the development of a simple stock market Investment Tracker application. It
starts with the basics of testing through the development of the base domain classes
(such as stock and investment), passes through the concepts of maintainable browser
code, and concludes with a full refactoring to a React.js application build on ECMA
Script 6 modules and automated build.
[v]
www.it-ebooks.info
Preface
Chapter 2, Your First Spec, helps you learn the thought process behind thinking
in terms of test-driven development. You will code your very first JavaScript
functionality driven by tests. You will also learn the basic functions of Jasmine
and how to structure your tests. Also demonstrated, is how Jasmine matchers work
and how you can create one of your own to improve your tests' code readability.
Chapter 4, Asynchronous Testing – AJAX, talks about the challenges in testing AJAX
requests and how you can use Jasmine to test any asynchronous code. You will learn
about Node.js and how to create a very simple HTTP server to use as a fixture to
your tests.
Chapter 5, Jasmine Spies, presents the concept of test doubles and how to use spies to
do behavior checking.
Chapter 6, Light Speed Unit Testing, helps you to learn about the issues with AJAX
testing and how you can make your tests run faster using stubs or fakes.
Chapter 7, Testing React Applications, introduces you to React, a library to build user
interfaces, and covers how you can use it to improve the concepts presented in
Chapter 3, Testing Frontend Code, to create richer and more maintainable applications,
of course, driven by tests.
Chapter 8, Build Automation, presents you with the power of automation. It introduces
you to webpack, a bundling tool for frontend assets. You will start to think in terms
of modules and their dependencies, and you will learn how to code your tests as
modules. You will also learn about packing and minifying the code to production
and how to automate this process. Finally, you are going to learn about running your
tests from a command line and how this can be used in a continuous integration
environment with Travis.ci.
[ vi ]
www.it-ebooks.info
Preface
Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.
Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
"We can include other contexts through the use of the include directive."
When we wish to draw your attention to a particular part of a code block, the relevant
lines or items are set in bold:
describe("Investment", function() {
it("should be of a stock", function() {
expect(investment.stock).toBe(stock);
});
});
New terms and important words are shown in bold. Words that you see on
the screen, for example, in menus or dialog boxes, appear in the text like this:
"Clicking the Next button moves you to the next screen."
[ vii ]
www.it-ebooks.info
Preface
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it helps
us develop titles that you will really get the most out of.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
[ viii ]
www.it-ebooks.info
Preface
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you could report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the Errata Submission Form
link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our website or added
to any list of existing errata under the Errata section of that title.
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all
media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
We appreciate your help in protecting our authors and our ability to bring you
valuable content.
Questions
If you have a problem with any aspect of this book, you can contact us at
[email protected], and we will do our best to address the problem.
[ ix ]
www.it-ebooks.info
www.it-ebooks.info
Getting Started with Jasmine
It is an exciting time to be a JavaScript developer; technologies have matured,
web browsers are more standardized, and there are new things to play with every
day. JavaScript has become an established language, and the Web is the true
open platform of today. We've seen the rise of single-page web applications, the
proliferation of Model View Controller (MVC) frameworks, such as Backbone.js
and AngularJS, the use of JavaScript on the server with Node.js, and even mobile
applications created entirely with HTML, JavaScript, and CSS using technologies
such as PhoneGap.
From its humble beginnings with handling HTML forms, to the massive applications
of today, the JavaScript language has come very far, and with it, a number of tools
have matured to ensure that you can have the same level of quality with it that you
have with any other language.
This book is about the tools that keep you in control of your JavaScript development.
[1]
www.it-ebooks.info
Getting Started with Jasmine
Besides that, you have issues with the language itself. Brendan Eich developed
JavaScript in just 10 days, under a lot of management pressure at Netscape. Although
it got itself right in its simplicity, first-class functions, and object prototypes, it also
introduced some problems with the attempt to make the language malleable and
allow it to evolve.
Every JavaScript object is mutable; this means that there is nothing you can do to
prevent a module from overwriting pieces of other modules. The following code
illustrates how simple it is to overwrite the global console.log function:
console.log('test');
>> 'test'
console.log = 'break';
console.log('test');
>> TypeError: Property 'log' of object #<Console> is not a function
This was a conscious decision on the language design; it allows developers to tinker
and add missing functionality to the language. But given such power, it is relatively
easy to make a mistake.
Another problem, is with how JavaScript deals with type. In other languages, an
expression like '1' + 1 would probably raise an error; in JavaScript, due to some
non-intuitive type coercion rules, the aforementioned code results in '11'. But the
main problem is in its inconsistency; on multiplication, a string is converted into a
number, so '3' * 4, is actually 12.
This can lead to some hard-to-find problems on big expressions. Suppose you have
some data coming from a server, and although you are expecting numbers, one value
came as a string:
var a = 1, b = '2', c = 3, d = 4;
var result = a + b + c * d;
These are just two common problems faced by developers. Throughout the book,
you are going to apply best practices and write tests to guarantee that you don't fall
into these, and other, pitfalls.
[2]
www.it-ebooks.info
Chapter 1
But before we can go any further, first we need to get some fundamentals right,
starting with what a test unit is.
A test unit is a piece of code that tests a functionality unit of the application code. But
sometimes, it can be tricky to understand what a functionality unit can be, so for that
reason, Dan North came up with a solution in the form of BDD, which is a rethink of
test-driven development (TDD).
In traditional unit testing practice, the developer is left with loose guidelines on how
to start the process of testing, what to test, how big a test should be, or even how to
call a test.
To fix these problems, Dan took the concept of user stories from the standard agile
construct, as a model on how to write tests.
For example, a music player application could have an acceptance criterion such as:
Given a player, when the song has been paused, then it should indicate that the
song is currently paused.
In Jasmine, this translates into a very expressive language that allows tests to be
written in a way that reflects actual business values. The preceding acceptance
criterion written as a Jasmine test unit would be as follows:
describe("Player", function() {
describe("when song has been paused", function() {
it("should indicate that the song is paused", function() {
});
});
});
[3]
www.it-ebooks.info
Getting Started with Jasmine
You can see how the criterion translates well into the Jasmine syntax. In the next
chapter, we will get into the details of how these functions work.
With Jasmine, as with other BDD frameworks, each acceptance criterion directly
translates to a test unit. For that reason, each test unit is usually called a spec, short
for specification. During the course of this book, we will be using this terminology.
Downloading Jasmine
Getting started with Jasmine is actually pretty simple.
While at the Jasmine website, you might notice that it is actually a live page
executing the specs contained in it. This is made possible by the simplicity of the
Jasmine framework, allowing it to be executed in the most diverse environments.
After you've downloaded the distribution and uncompressed it, you can open the
SpecRunner.html file on your browser. It will show the results of a sample test
suite (including the acceptance criterion we showed you earlier):
This SpecRunner.html file is a Jasmine browser spec runner. It is a simple HTML file
that references the Jasmine code, the source files, and the test files. For convention
purposes, we are going to refer to this file simply as runner.
[4]
www.it-ebooks.info
Chapter 1
You can see how simple it is by opening it on a text editor. It is a small HTML file
that references the Jasmine source:
<script src="lib/jasmine-2.1.3/jasmine.js"></script>
<script src="lib/jasmine-2.1.3/jasmine-html.js"></script>
<script src="lib/jasmine-2.1.3/boot.js"></script>
The runner references a special SpecHelper.js file that contains code shared
between specs:
<script type="text/javascript" src="spec/SpecHelper.js"></script>
Although, for now, we are running the specs in the browser, in Chapter 8, Build
Automation, we are going to make the same specs and code run on a headless
browser, such as PhantomJS, and have the results written on the console.
And although not covered in this book, Jasmine can also be used to test server-side
JavaScript code written for environments such as Node.js.
This Jasmine flexibility is amazing, because you can use the same tool to test all sorts
of JavaScript code.
[5]
www.it-ebooks.info
Getting Started with Jasmine
Summary
In this chapter, you saw some of the motivations behind testing a JavaScript
application. I showed you some common pitfalls of the JavaScript language
and how BDD and Jasmine both help you to write better tests.
You have also seen how easy it is to download and get started with Jasmine.
In the next chapter, you are going to learn how to think in BDD and code your
very first spec.
[6]
www.it-ebooks.info
Your First Spec
This chapter is about the basics, and we are going to guide you through how to write
your first spec, think in test-first terms for development, and also show you all the
available global Jasmine functions. By the end of the chapter, you should know how
Jasmine works and be ready to start doing your first tests by yourself.
The following screenshot of the form illustrates how a user might create a new
investment on this application:
This form will allow the input of three values that define an investment:
• First, we will input Symbol, which represents which company (stock) the
user is investing in
• Then, we will input how many Shares the user has bought (or invested in)
• Finally, we will input how much the user has paid for each share
(Share price)
[7]
www.it-ebooks.info
Your First Spec
If you are unfamiliar with how the stock market works, imagine you are shopping
for groceries. To make a purchase, you must specify what you are buying, how many
items you are buying, and how much you are going to pay. These concepts translate
to an investment as:
Once the user has added an investment, it must be listed along with their other
investments, as shown in the following screenshot:
The idea is to display how well their investments are going. Since the prices of the
stocks fluctuate over time, the difference between the price the user has paid and
the current price indicates whether it is a good (profit) or a bad (loss) investment.
In the preceding screenshot, we can see that the user has two investments:
This is a very simple application, and we will get a deeper understanding of its
functionality as we go on with its development.
[8]
www.it-ebooks.info
Chapter 2
Using the standalone distribution downloaded in the previous chapter, the first
thing we need to do is create a new spec file. This file can be created anywhere,
but it is a good idea to stick to a convention, and Jasmine already has a good one:
specs should be in the /spec folder. Create an InvestmentSpec.js file and add
the following lines:
describe("Investment", function() {
});
The describe function is a global Jasmine function used to define test contexts.
When used as the first call in a spec, it creates a new test suite (a collection of test
cases). It accepts two parameters, which are as follows:
});
});
[9]
www.it-ebooks.info
Your First Spec
Execute the spec by opening the runner on the browser. The following output
can be seen:
It might sound strange to have an empty spec passing, but in Jasmine, as with other
test frameworks, a failed assertion is required to make the spec fail.
An assertion (or expectation) is a comparison between two values that must result
in a boolean value. The assertion is only considered a success if the result of the
comparison is true.
In Jasmine, assertions are written using the global Jasmine function expect, along
with a matcher that indicates what comparison must be made with the values.
Regarding the current spec (it is expected that the investment is of a stock), in
Jasmine this translates to the following code:
describe("Investment", function() {
it("should be of a stock", function() {
expect(investment.stock).toBe(stock);
});
});
Add the preceding highlighted code to the InvestmentSpec.js file. The expect
function takes only one parameter, which defines the actual value, or in other words,
what is going to be tested—investment.stock—and expects the chaining call to a
matcher function, which in this case is toBe. That defines the expected value, stock,
and the comparison method to be performed (to be the same).
Behind the scenes, Jasmine makes a comparison to check whether the actual value
(investment.stock) and expected value (stock) are the same, and if they are not,
the test fails.
[ 10 ]
www.it-ebooks.info
Chapter 2
With the assertion written, the spec that previously passed has now failed, as shown
in the following screenshot:
This spec failed because, as the error message states, investment is not defined.
The idea here is to do only what the error is indicating us to do, so although you
might feel the urge to write something else, for now let's just create this investment
variable with an Investment instance in the InvestmentSpec.js file, as follows:
describe("Investment", function() {
it("should be of a stock", function() {
var investment = new Investment();
expect(investment.stock).toBe(stock);
});
});
Don't worry that the Investment() function doesn't exist yet; the spec is about to
ask for it on the next run, as follows:
You can see that the error has changed to Investment is not defined. It now asks
for the Investment function. So, create a new Investment.js file in the src folder
and add it to the runner, as shown in the following code:
<!-- include source files here... -->
<script type="text/javascript" src="src/Investment.js"></script>
[ 11 ]
www.it-ebooks.info
Your First Spec
This makes the error change. It now complains about the missing stock variable, as
shown in the following screenshot:
One more time, we feed the code it is asking for into the InvestmentSpec.js file,
as shown in the following code:
describe("Investment", function() {
it("should be of a stock", function() {
var stock = new Stock();
var investment = new Investment();
expect(investment.stock).toBe(stock);
});
});
The error changes again; this time it is about the missing Stock function:
Create a new file in the src folder, name it Stock.js, and add it to the runner. Since
the Stock function is going to be a dependency of Investment, we should add it just
before Investment.js:
<!-- include source files here... -->
<script type="text/javascript" src="src/Stock.js"></script>
<script type="text/javascript" src="src/Investment.js"></script>
[ 12 ]
www.it-ebooks.info
Chapter 2
Finally, the error is about the expectation, as shown in the following screenshot:
To fix this and complete this exercise, open the Investment.js file inside the src
folder, and add the reference to the stock parameter:
function Investment (stock) {
this.stock = stock;
};
The drive to write code must come from a spec that has failed. You
must not write code unless its purpose is to fix a failed spec.
[ 13 ]
www.it-ebooks.info
Your First Spec
describe("Investment", function() {
it("should be of a stock", function() {
var stock = new Stock();
var investment = new Investment({
stock: stock,
shares: 100
});
expect(investment.stock).toBe(stock);
});
You can see that apart from having written the new spec, we have also changed the
call to the Investment constructor to support the new shares parameter.
[ 14 ]
www.it-ebooks.info
Chapter 2
The code is now refactored. We can run the tests to see that only the new spec fails,
as shown here:
To fix this, change the Investment constructor to make the assignment to the shares
property, as follows:
function Investment (params) {
this.stock = params.stock;
this.shares = params.shares;
};
But as you can see, the following code, which instantiates Stock and Investment, is
duplicated on both specs:
var stock = new Stock();
var investment = new Investment({
stock: stock,
shares: 100
});
[ 15 ]
www.it-ebooks.info
Your First Spec
Refactor the previous specs by extracting the setup code using the beforeEach
function:
describe("Investment", function() {
var stock, investment;
beforeEach(function() {
stock = new Stock();
investment = new Investment({
stock: stock,
shares: 100
});
});
This looks much cleaner; we not only removed the code duplication, but also
simplified the specs. They became much easier to read and maintain since their
only responsibility now is to fulfill the expectation.
There is also a teardown function (afterEach) that sets the code to be executed after
each spec. It is very useful in situations where a cleanup is required after each spec.
We will see an example of its application in Chapter 6, Light Speed Unit Testing.
To finish the specification of Investment, add the remaining two specs to the
InvestmentSpec.js file, inside the spec folder:
describe("Investment", function() {
var stock;
var investment;
beforeEach(function() {
stock = new Stock();
investment = new Investment({
stock: stock,
shares: 100,
sharePrice: 20
[ 16 ]
www.it-ebooks.info
Chapter 2
});
});
Run the specs to see them fail, as shown in the following screenshot:
Add the following code to fix them in the Investment.js file inside the src folder:
function Investment (params) {
this.stock = params.stock;
this.shares = params.shares;
this.sharePrice = params.sharePrice;
this.cost = this.shares * this.sharePrice;
};
[ 17 ]
www.it-ebooks.info
Your First Spec
Run the specs for the last time to see them pass:
It is important to always see a spec fail before writing the code to fix it;
otherwise, how would you know that you really need to fix it? Imagine
this as a way to test the test.
Nested describes
Nested describes are useful when you want to describe similar behavior between
specs. Suppose we want the following two new acceptance criteria:
• Given an investment, when its stock share price valorizes, it should have
a positive return on investment (ROI)
• Given an investment, when its stock share price valorizes, it should be
a good investment
Both these criteria share the same behavior when the investment's stock share
price valorizes.
To translate this into Jasmine, you can nest a call to the describe function inside the
existing one in the InvestmentSpec.js file (I removed the rest of the code for the
purpose of demonstration; it is still there):
describe("Investment", function()
describe("when its stock share price valorizes", function() {
});
});
It should behave just like the outer one, so you can add specs (it) and use the setup
and teardown functions (beforeEach, afterEach).
[ 18 ]
www.it-ebooks.info
Chapter 2
So, we can add a setup function to this new describe function that changes the
share price of the stock, so that it's greater than the share price of the investment:
describe("Investment", function() {
var stock;
var investment;
beforeEach(function() {
stock = new Stock();
investment = new Investment({
stock: stock,
shares: 100,
sharePrice: 20
});
});
[ 19 ]
www.it-ebooks.info
Your First Spec
Investment.prototype.isGood = function() {
return this.roi() > 0;
};
You can run the specs and see that they pass:
Understanding matchers
By now, you've already seen plenty of usage examples for matchers and probably
can feel how they work.
You have seen how to use the toBe and toEqual matchers. These are the two
base built-in matchers available in Jasmine, but we can extend Jasmine by writing
matchers of our own.
So, to really understand how Jasmine matchers work, we need to create one ourselves.
[ 20 ]
www.it-ebooks.info
Chapter 2
Custom matchers
Consider this expectation from the previous section:
expect(investment.isGood()).toEqual(true);
Although it works, it is not very expressive. Imagine if we could instead rewrite it as:
expect(investment).toBeAGoodInvestment();
Although you can put this new matcher definition inside the InvestmentSpec.js
file, Jasmine already has a default place to add custom matchers, the SpecHelper.js
file, inside the spec folder. If you are using Standalone Distribution, it already comes
with a sample custom matcher; delete it and let's start from scratch.
The function being defined here is not the matcher itself but a factory function
to build the matcher. Its purpose, once called is to return an object containing a
compare function, as follows:
jasmine.addMatchers({
toBeAGoodInvestment: function () {
return {
compare: function (actual, expected) {
// matcher definition
}
};
}
});
[ 21 ]
www.it-ebooks.info
Exploring the Variety of Random
Documents with Different Content
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the terms
of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth in
paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com