Jasmine JavaScript Testing 2nd Edition Test your JavaScript applications efficiently using Jasmine and React js Paulo Ragonha - Discover the ebook with all chapters in just a few seconds
Jasmine JavaScript Testing 2nd Edition Test your JavaScript applications efficiently using Jasmine and React js Paulo Ragonha - Discover the ebook with all chapters in just a few seconds
com
https://ebookmeta.com/product/jasmine-javascript-
testing-2nd-edition-test-your-javascript-applications-
efficiently-using-jasmine-and-react-js-paulo-ragonha/
OR CLICK HERE
DOWLOAD EBOOK
https://ebookmeta.com/product/developing-a-react-js-edge-the-
javascript-library-for-user-interfaces-2nd-edition-richard-feldman/
ebookmeta.com
https://ebookmeta.com/product/testing-javascript-applications-1st-
edition-lucas-da-costa/
ebookmeta.com
https://ebookmeta.com/product/the-road-to-react-your-journey-to-
master-react-in-javascript-2023-edition-robin-wieruch/
ebookmeta.com
https://ebookmeta.com/product/northeast-india-a-political-history-1st-
edition-samrat-choudhury/
ebookmeta.com
https://ebookmeta.com/product/concepts-and-real-time-applications-of-
deep-learning-1st-edition-smriti-srivastava/
ebookmeta.com
https://ebookmeta.com/product/brand-by-hand-blisters-calluses-and-
clients-a-life-in-design-jon-contino/
ebookmeta.com
https://ebookmeta.com/product/a-political-economy-of-free-zones-in-
gulf-arab-states-1st-edition-robert-mogielnicki/
ebookmeta.com
https://ebookmeta.com/product/sing-to-victory-song-in-soviet-society-
during-world-war-ii-1st-edition-suzanne-ament/
ebookmeta.com
Productizing Quantum Computing: Bring Quantum Computing
Into Your Organization 1st Edition Dhairyya Agarwal
https://ebookmeta.com/product/productizing-quantum-computing-bring-
quantum-computing-into-your-organization-1st-edition-dhairyya-
agarwal-2/
ebookmeta.com
[1]
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
Another Random Document on
Scribd Without Any Related Topics
‘I did not say so; but I think, perhaps, on the whole, that to go a little
further, and see a little more, would be best both for you and Kate.’
‘Exactly,’ said Ombra, with bitterness, nodding her head in a derisive
assent.
Kate looked on with wistful and startled eyes. It was almost the first time
that the idea of real dissension between these two had crossed her mind; and
still more this infinitely startling doubt whether all that was said to her was
true. At least there had been concealment; and was it really, truly the good
of Ombra and Kate, or some private arrangement with Uncle Courtenay,
that was in her aunt’s mind. This suggestion came suddenly into her very
heart, wounding her as with an arrow; and from that day, though sometimes
lessening and sometimes deepening, the cloud upon Ombra’s face came
back. But as she grew less amiable, she grew more powerful. Henceforward
the party became guided by her wayward fancies. She took a sudden liking
for one of the quietest secluded places—a village on the little blue lake of
Zug—and there they settled for some time, without rhyme or reason. Green
slopes, with grey stone-peaks above, and glimpses of snow beyond, shut in
this lake-valley. I agree with Ombra that it is very sweet in its stillness, the
lake so blue, the air so clear, and the noble nut-bearing trees so umbrageous,
shadowing the pleasant châlets. In the centre was a little white-washed
village church among its graves, its altar all decked with stately May lilies,
the flowers of the Annunciation. The church had no beauty of architecture,
no fine pictures—not even great antiquity to recommend it; but Ombra was
fond of the sunshiny, still place. She would go there when she was tired,
and sit down on one of the rush-bottomed chairs, and sometimes was to be
seen kneeling furtively on the white altar steps.
Kate, who roamed up and down everywhere, and had soon all the facility
of a young mountaineer, would stop at the open church-door as she came
down from the hills, alpenstock in hand, sunburnt and agile as a young
Diana.
‘You are not going to turn a Roman Catholic, Ombra?’ she said. ‘I think
it would make my aunt very unhappy.’
‘I am not going to turn anything,’ said Ombra. ‘I shall never be different
from what I am—never any better. One tries and tries, and it is no good.’
‘Then stop trying, and come up on the hills and shake it off,’ said Kate.
‘Perhaps I might if I were like you; but I am not like you.’
‘Or let us go on, and see people and do things again—do all sorts of
things. I like this little lake,’ said Kate. ‘One has a home-feeling. I almost
think I should begin to poke about the cottages, and find fault with the
people, if we were to stay long. But that is not your temptation, Ombra.
Why do you like to stay?’
‘I stay because it is so still—because nobody comes here, nothing can
happen here; it must always be the same for ever and for ever and ever!’
cried Ombra. ‘The hills and the deep water, and the lilies in the church—
which are artificial, you know, and cannot fade.’
Kate did not understand this little bitter jibe at the end of her cousin’s
speech; but was overwhelmed with surprise when Ombra next morning
suggested that they should resume their journey. They were losing their
time where they were, she said; and as, if they were to go to Italy for the
Winter, it would be necessary to return by Switzerland next year, she
proposed to strike off from the mountains at this spot, to go to Germany, to
the strange old historical cities that were within reach. ‘Kate should see
Nuremberg,’ she said; and Kate, to her amazement, found the whole matter
settled, and the packing commenced that day. Ombra managed the whole
journey, and was a practical person, handy and rational, until they came to
that old-world place, where she became reveuse and melancholy once more.
‘Do you like this better than Switzerland?’ Kate asked, as they looked
down from their windows along the three-hundred-years-old street, where it
was so strange to see people walking about in ordinary dresses and not in
trunkhose and velvet mantles.
‘I don’t care for any place. I have seen so many, and one is so much like
another,’ said Ombra. ‘But look, Kate, there is one advantage. Anything
might happen here; any one might be coming along those streets and you
would never feel surprised. If I were to see my father walking quietly this
way, I should not think it at all strange.’
‘But, Ombra—he is dead!’ said Kate, shrinking a little, with natural
uneasiness.
‘Yes, he is dead, but that does not matter. Look down that hazy street
with all the gables. Any one might be coming—people whom we have
forgotten—even,’ she said, pressing Kate’s arm, ‘people who have forgotten
us.’
‘Oh! Ombra, how strangely you speak! People that care for you don’t
forget you,’ cried Kate.
‘That does not mend the matter,’ said Ombra, and withdrew hurriedly
from the window.
Poor Kate tried very hard to make something out of it, but could not; and
therefore she shrugged her shoulders and gave her head a little shake, and
went to her German, which she was working at fitfully, to make the best of
her opportunities. The German, though she thought sometimes it would
break her heart, was not so hard as Ombra; and even the study of languages
had to her something amusing in it.
One of the young waiters in the hotel kept a dictionary in the staircase
window, and studied it as he flew up and down stairs for a new word to
experiment with upon the young ladies; and another had, by means of the
same dictionary, set up a flirtation with Maryanne; so fun was still possible,
notwithstanding all; and whether it was by the mountain paths, or in those
hazy strange old streets, Kate walked with her head, as it were, in the
clouds, in a soft rapture of delight and pleasantness, taking in all that was
sweet and lovely and good, and letting the rest drop off from her like a
shower of rain. She even ceased to think of Ombra’s odd ways—not out of
want of consideration, but with the facility which youth has for taking
everything for granted, and consenting to whatever is. It was a great pity,
but it could not be helped, and one must make the best of it all the same.
And thus the Summer passed on, full of wonders and delights. Mrs.
Anderson and her daughter, and even Francesca, were invaluable to the
ignorant girl. They knew how everything had to be done; they were
acquainted alike with picture-galleries and railway-tickets, and knew even
what to say about every work of art—an accomplishment deeply amazing to
Kate, who did not know what to say about anything, and who had several
times committed herself by praising vehemently some daub which was
beyond the reach of praise. When she made such a mistake as this, her
mortification and shame were great; but unfortunately her pride made her
hold by her opinion. They saw so many pictures, so many churches, so
much that was picturesque and beautiful, that her brain was in a maze, and
her intellect had become speechless.
They took their way across the mountains in Autumn, getting entangled
in the vast common tide of travellers to Italy; and, after all, Francesca’s
words came true, and it was a relief to Kate to get back into the stream—it
relieved the strain upon her mind. Instead of thinking of more and lovelier
pictures still, she was pleased to rest and see nothing; and even—a
confession which she was ashamed to make to herself—Kate was as much
delighted with the prospect of mundane pleasures as she had been with the
scenery. Society had acquired a new charm. She had never been at anything
more than ‘a little dance,’ or a country concert, and balls and operas held
out their arms to her. One of the few diplomatic friends whom Mrs.
Anderson had made in her consular career was at Florence; and even Mr.
Courtenay could not object to his niece’s receiving the hospitalities of the
Embassy. She was to ‘come out’ at the Ambassador’s ball—not in her full-
blown glory, as an heiress and a great lady, but as Mrs. Anderson’s niece, a
pretty, young, undistinguished English girl. Kate knew nothing about this,
nor cared. She threw herself into the new joys as she had done into the old.
A new chapter, however it might begin, was always a pleasant thing in her
fresh and genial life.
CHAPTER XXXIV.
Florence altogether was full of pleasant novelty to the young traveller. To
find herself living up two pair of stairs, with windows overlooking the
Arno, and at a little distance the quaint buildings of the Ponte Vecchio, was
as great a change as the first change had been from Langton-Courtenay to
the little Cottage at Shanklin. Mrs. Anderson’s apartment on the second
floor of the Casa Graziana was not large. There was a drawing-room which
looked to the front, and received all the sunshine which Florentine skies
could give; and half a mile off, at the other end of the house, there was a
grim and spare dining-room, furnished with the indispensable tables and
chairs, and with a curious little fireplace in the corner, raised upon a slab of
stone, as on a pedestal. It would be difficult to tell how cold it was here as
the Winter advanced; but in the salone it was genial as Summer whenever
the sun shone. The family went, as it were, from Nice to Inverness when
they went from the front to the back, for their meals. Perhaps it might have
been inappropriate for Miss Courtenay of Langton-Courtenay to live up two
pair of stairs; but it was not at all unsuitable for Mrs. Anderson; and, indeed,
when Lady Barker, who was Mrs. Anderson’s friend, came to call, she was
much surprised by the superior character of the establishment. Lady Barker
had been a Consul’s daughter, and had risen immensely in life by marrying
the foolish young attaché, whom she now kept in the way he ought to go.
She was not the Ambassadress, but the Ambassadress’s friend, and a
member of the Legation; and, though she was now in a manner a great lady
herself, she remembered quite well what were the means of the Andersons,
and knew that even the terzo piano of a house on the Lung-Arno was more
than they could have ventured on in the ancient days.
‘What a pretty apartment,’ she said; ‘and how nicely situated! I am afraid
you will find it rather dear. Florence is so changed since your time. Do you
remember how cheap everything used to be in the old days? Well, if you
will believe me, you pay just fifteen times as much for every article now.’
‘So I perceive,’ said Mrs. Anderson. ‘We give a thousand francs for these
rooms, which ought not to be more than a hundred scudi—and without even
the old attraction of a pleasant accessible Court.’
Lady Barker opened her eyes—at once, at the fact of Mrs. Anderson
paying a thousand francs a month for her rooms, and at her familiar
mention of the pleasant Court.
‘Oh, there are some very pleasant people here now!’ she said; ‘if your
young ladies are fond of dancing, I think I can help them to some
amusement. Lady Granton will send you cards for her ball. Is Ombra
delicate?—do you still call her Ombra? How odd it is that you and I, under
such different circumstances, should meet here!’
‘Yes—very odd,’ said Mrs. Anderson; ‘and yet I don’t know. People who
have been once in Italy always come back. There is a charm about it—a
——’
‘Ah, we didn’t think so once!’ said Lady Barker, with a laugh. She could
remember the time when the Andersons, like so many other people
compelled to live abroad, looked upon everything that was not English with
absolute enmity. ‘You used to think Italy did not agree with your daughter,’
she said; ‘have you brought her for her health now?’
‘Oh no! Ombra is quite well; she is always pale,’ said Mrs. Anderson.
‘We have come rather on account of my niece—not for her health, but
because she had never seen anything out of her own country. We think it
right that she should make good use of her time before she comes of age.’
‘Oh! will she come of age?’ said Lady Barker, with a glance of laughing
curiosity. She decided that the pretty girl at the window, who had two or
three times broken into the conversation, was a great deal too pretty to be
largely endowed by fortune; and smiled at her old friend’s grandiloquence,
which she remembered so well. She made a very good story of it at the little
cosy dinner-party at the Embassy that evening, and prepared the good
people for some amusement. ‘A pretty English country girl, with some
property, no doubt,’ she said. ‘A cottage ornée, most likely, and some fields
about it; but her aunt talks as if she were heiress to a Grand Duke. She has
come abroad to improve her mind before she comes of age.’
‘And when she goes back there will be a grand assemblage of the
tenantry, no doubt, and triumphal arches, and all the rest of it,’ said another
of the fine people.
‘So Mrs. Vice-Consul allows one to suppose,’ said Lady Barker. ‘But she
is so pretty—prettier than anything I have seen for ages; and Ombra, too, is
pretty, the late Vice-Consul’s heiress. They will far furore—two such new
faces, and both so English; so fresh; so gauche!’
This was Lady Barker’s way of backing her friends; but the friends did
not know of it, and it procured them their invitation all the same, and Lady
Granton’s card to put on the top of the few other cards which callers had
left. And Mrs. Anderson came to be, without knowing it, the favourite joke
of the ambassadorial circle. Mrs. Vice-Consul had more wonderful sayings
fastened upon her than she ever dreamt of, and became the type and symbol
of the heavy British matron to that lively party. Her friend made her out to
be a bland and dignified mixture of Mrs. Malaprop and Mrs. Nickleby.
Meanwhile, she had a great many things to do, which occupied her, and
drove even her anxieties out of her mind. There was the settling down—the
hiring of servants and additional furniture, and all the trifles necessary to
make their rooms ‘comfortable;’ and then the dresses of the girls to be put
in order, and especially the dress in which Kate was to make her first
appearance.
Mrs. Anderson had accepted Mr. Courtenay’s conditions; she had
acquiesced in the propriety of keeping silent as to Kate’s pretensions, and
guarding her from all approach of fortune-hunters. There was even
something in this which was not disagreeable to her maternal feelings; for
to have Kate made first, and Ombra second, would not have been pleasant.
But still, at the same time, she could not restrain a natural inclination to
enhance the importance of her party by a hint—an inference. That little
intimation about Kate’s coming of age, she had meant to tell, as indeed it
did, more than she intended; and now her mind was greatly exercised about
her niece’s ball-dress. ‘White tarlatane is, of course, very nice for a young
girl,’ she said, doubtfully, ‘it is all my Ombra has ever had; but, for Kate,
with her pretensions——’
This was said rather as one talks to one’s self, thinking aloud, than as
actually asking advice.
‘But I thought Kate in Florence was to be simply your niece,’ said
Ombra, who was in the room. ‘To make her very fine would be bad taste;
besides,’ she added, with a little sigh, ‘Kate would look well in white calico.
Nature has decked her so. I suppose I never, at my best, was anything like
that.’
Ombra had improved very much since their arrival in Florence. Her
fretfulness had much abated, and there was no envy in this sigh.
‘At your best, Ombra! My foolish darling, do you think your best is
over?’ said the mother, with a smile.
‘I mean the bloom,’ said Ombra. ‘I never had any bloom—and Kate’s is
wonderful. I think she gives a pearly, rosy tint to the very air. I was always a
little shadow, you know!’
‘You will not do yourself justice,’ cried Mrs. Anderson. ‘Oh! Ombra, if
you only knew how it grieves me! You draw back, and you droop into that
dreamy, melancholy way; there is always a mist about you. My darling, this
is a new place, you will meet new people, everything is fresh and strange.
Could you not make a new beginning, dear, and shake it off!’
‘I try,’ said Ombra, in a low tone.
‘I don’t want to be hard upon you, my own child; but, then, dear, you
must blame yourself, not any one else. It was not his fault.’
‘Please don’t speak of it,’ cried the girl. ‘If you could know how
humbled I feel to think that it is that which has upset my whole life! Ill-
temper, jealousy, envy, meanness—pleasant things to have in one’s heart! I
fight with them, but I can’t overcome them. If I could only “not care!” How
happy people are who can take things easily, and who don’t care!’
‘Very few people do,’ said Mrs. Anderson. ‘Those who have command
of themselves don’t show their feelings, but most people feel more or less.
The change, however, will do you good. And you must occupy yourself, my
love. How nicely you used to draw, Ombra! and you have given up
drawing. As for poetry, my dear, it is very pretty—it is very, very pretty—
but I fear it is not much good.’
‘It does not sell, you mean, like novels.’
‘I don’t know much about novels; but it keeps you always dwelling upon
your feelings. And then, if they were ever published, people would talk.
They would say, “Where has Ombra learned all this? Has she been as
unhappy as she says? Has she been disappointed?” My darling, I think it
does a girl a great deal of harm. If you would begin your drawing again!
Drawing does not tell any tales.’
‘There is no tale to tell,’ cried Ombra. Her shadowy face flushed with a
colour which, for the moment, was as bright as Kate’s, and she got up
hurriedly, and began to arrange some books at a side-table, an occupation
which carried her out of her mother’s way; and then Kate came in, carrying
a basket of fruit, which she and Francesca had bought in the market. There
were scarcely any flowers to be had, she complained, but the grapes, with
their picturesque stems, and great green leaves, stained with russet, were
almost as ornamental. A white alabaster tazza, which they had bought at
Pisa, heaped with them, was almost more effective, more characteristic than
flowers.
‘I have been trying to talk to the market-women,’ she said, ‘down in that
dark, narrow passage, by the Strozzi Palace. Francesca knows all about it.
How pleasant it is going with Francesca—to hear her chatter, and to see her
brown little face light up! She tells me such stories of all the people as we
go.’
‘How fond you are of stories, Kate!’
‘Is it wrong? Look, auntie, how lovely this vine-branch looks! England
is better for some things, though. There will still be some clematis over our
porch—not in flower, perhaps, but in that downy, fluffy stage, after the
flower. Francesca promises me everything soon. Spring will begin in
December, she says, so far as the flowers go, and then we can make the
salone gay. Do you know there are quantities of English people at the hotel
at the corner? I almost thought I heard some one say my name as I went by.
I looked up, but I could not see anybody I knew.’
‘I hope there is nobody we know,’ cried Ombra, under her breath.
‘My dear children,’ said Mrs. Anderson, with solemnity, ‘you must
recognise this principle in Italy, that there are English people everywhere;
and wherever there are English people, there is sure to be some one whom
you know, or who knows you. I have seen it happen a hundred times; so
never mind looking up at the windows, Kate—you may be sure we shall
find out quite soon enough.’
‘Well, I like people,’ said Kate, carelessly, as she went out of the room.
‘It will not be any annoyance to me.’
‘She does not care,’ said Ombra—‘it is not in her nature. She will always
be happy, because she will never mind. One is the same as another to her. I
wish I had that happy disposition. How strange it is that people should be so
different! What would kill me would scarcely move her—would not cost
her a tear.’
‘Ombra, I am not so sure——’
‘Oh! but I am sure, mamma. She does not understand how things can
matter so much to me. She wonders—I can see her look at me when she
thinks I don’t notice. She seems to say, “What can Ombra mean by it?—
how silly she is to care!”’
‘But you have not taken Kate into your confidence?’ said Mrs. Anderson,
in alarm.
‘I have not taken any one into my confidence—I have no confidence to
give,’ said Ombra, with the ready irritation which had come to be so
common with her. The mother bore it, as mothers have to do, turning away
with a suppressed sigh. What a difference the last year had made on Ombra!
—oh! what a thing love was to make such a difference in a girl! This is
what Mrs. Anderson said to herself with distress and pain; she could
scarcely recognise her own child in this changed manifestation, and she
could not approve, or even sympathise with her, in the degree, at least,
which Ombra craved.
CHAPTER XXXV.
The fact was that Ombra, as she said, had not given her confidence to any
one; she had betrayed herself to her mother in her first excitement, when
she had lost command of herself; but that was all. A real and full confidence
she had never given. Ombra’s love of sympathy was great, but it was not
accompanied, as it generally is, by that open heart which finds comfort in
disclosing its troubles. Her heart was not open. She neither revealed herself
nor divined others; she was not selfish, nor harsh in temper and disposition;
but all that she was certain of was her own feelings. She did not know how
to find out what other people were feeling or thinking, consequently she had
a very imperfect idea of those about her, and seldom found out for herself
what was going on in their minds. This limited her powers of sympathy in a
wonderful way, and it was this which was at the root of all her trouble. She
had been wooed, but only when it came to a conclusion had she really
known what that wooing meant. In her ignorance she had refused the man
whom she was already beginning to love, and then had gone on to think
about him, after he had revealed himself—to understand all he had been
meaning—to love him, with the consciousness that she had rejected him,
and with the fear that his affections were being transferred to her cousin.
This was what gave the sting to it all, and made poor Ombra complain so
mournfully of her temper. She did not divine what her love meant till it was
too late; and then she resented the fact that it was too late—resented the
reserve which she had herself imposed upon him, the friendly demeanour
she had enjoined. She had begged him, when she rejected him, as the
greatest of favours, to keep up his intercourse with the family, and be as
though this episode had never been. And when the poor fellow obeyed her
she was angry with him. I do not know whether the minds of men are ever
similarly affected, but this is a weakness not uncommon with women. And
then she took his subdued tone, his wistful looks, his seldom approaches to
herself, as so many instances that he had got over what she called his folly.
Why should he continue to nourish his folly when she had so promptly
announced her indifference? And then it was that it became apparent to her
that he had transferred his affections to Kate. As it happened, by the fatality
which sometimes attends such matters, the unfortunate young man never
addressed Kate, never looked at her, but Ombra found him out. When Kate
was occupied by others, her cousin took no notice; but when that one step
approached, that one voice addressed her, Ombra’s eyes and ears were like
the lynx. Kate was unconscious of the observation, by means of being
absolutely innocent; and the hero himself was unconscious for much the
same reason, and because he felt sure that his hopeless devotion to his first
love must be so plain to her as to make any other theory on the subject out
of the question. But Ombra, who was unable to tell what eyes meant, or to
judge from the general scope of action, set up her theory, and made herself
miserable. She had been wretched when watching ‘them;’ she was wretched
to go away and be able to watch them no longer. She had left home with a
sense of relief, and yet the news that they were not to return home for the
winter smote her like a catastrophe. Even the fact that he had loved her once
seemed a wrong to her, for then she did not know it; and since then had he
not done her the cruel injury of ceasing to love her?
Poor Ombra! this was how she tormented herself; and up to this moment
any effort she had made to free herself, to snap her chains, and be once
more rational and calm, seemed but to have dug the iron deeper into her
soul. Nothing cuts like an imaginary wrong. The sufferer would pardon a
real injury a hundred times while nursing and brooding over the supposed
one. She hated herself, she was ashamed, disgusted, revolted by the new
exhibitions of unsuspected wickedness, as she called it, in her nature. She
tried and tried, but got no better. But in the meantime all outward
possibilities of keeping the flame alight being withdrawn, her heart had
melted towards Kate. It was evident that in Kate’s lighter and more
sunshiny mind there was no room for such cares as bowed down her own;
and with a yearning for love which she herself scarcely understood, she
took her young cousin, who was entirely guiltless, into her heart.
Kate and she were sitting together, the morning of the ball to which the
younger girl looked forward so joyfully. Ombra was not unmoved by its
approach, for she was just one year over twenty, an age at which balls are
still great events, and not unapt to influence life. Her heart was a little
touched by Kate’s anxious desire that her dress and ornaments should be as
fresh and pretty and valuable as her own. It was good of her; to be sure,
there was no reason why one should wish to outshine the other; but still
Kate had been brought up a great lady, and Ombra was but the Consul’s
daughter. Therefore her heart was touched, and she spoke.
‘It does not matter what dress I have, Kate; I shall look like a shadow all
the same beside you. You are sunshine—that was what you were born to be,
and I was born in the shade.’
‘Don’t make so much of yourself, Ombra mia,’ said Kate. ‘Sunshine is
all very well in England, but not here. Am I to be given over to the
Englishmen and the dogs, who walk in the sun?’
A cloud crossed Ombra’s face at this untoward suggestion.
‘The Englishmen as much as you please,’ she said; and then, recovering
herself with an effort, ‘I wonder if I shall be jealous of you, Kate? I am a
little afraid of myself. You so bright, so fresh, so ready to make friends, and
I so dull and heavy as I am, besides all the other advantages on your side. I
never was in society with you before.’
‘Jealous of me!’ Kate thought it was an admirable joke. She laughed till
the tears stood in her bright eyes. ‘But then there must be love before there
is jealousy—or, so they say in books. Suppose some prince appears, and we
both fall in love with him? But I promise you, it is I who shall be jealous. I
will hate you! I will pursue you to the ends of the world! I will wear a
dagger in my girdle, and when I have done everything else that is cruel, I
will plunge it into your treacherous heart! Oh! Ombra, what fun!’ cried the
heroine, drying her dancing eyes.
‘That is foolish—that is not what I mean,’ said serious Ombra. ‘I am
very much in earnest. I am fond of you, Kate——’
This was said with a little effort; but Kate, unconscious of the effort,
only conscious of the love, threw her caressing arm round her cousin’s
waist, and kissed her.
‘Yes,’ she said, softly; ‘how strange it is, Ombra! I, who had nobody that
cared for me,’ and held her close and fast in the tender gratitude that filled
her heart.
‘Yes, I am fond of you,’ Ombra continued; ‘but if I were to see you
preferred to me—always first, and I only second, more thought of, more
noticed, better loved! I feel—frightened, Kate. It makes one’s heart so sore.
One says to oneself, “It is no matter what I do or say. It is of no use trying
to be amiable, trying to be kind—she is sure to be always the first. People
love her the moment they see her; and at me they never look.” You don’t
know what it is to feel like that.’
‘No,’ said Kate, much subdued; and then she paused. ‘But, Ombra, I am
always so pleased—I have felt it fifty times; and I have always been so
proud. Auntie and I go into a corner, and say to each other, “What nice
people these are—they understand our Ombra—they admire her as she
should be admired!” We give each other little nudges, and nod at each other,
and are so happy. You would be the same, of course, if—though it don’t
seem likely——’ And here Kate broke off abruptly, and blushed and
laughed.
‘You are the youngest,’ said Ombra—‘that makes it more natural in your
case. And mamma, of course, is—mamma—she does not count. I wonder—
I wonder how I shall take it—in my way or in yours?’
‘Are you so sure it will happen?’ said Kate, laughing. Kate herself did
not dislike the notion very much. She had not been brought up with that
idea of self-sacrifice which is inculcated from their cradles on so many
young women. She felt that it would be pleasant to be admired and made
much of; and even to throw others into the shade. She did not make any
resolutions of self-renunciation. The visionary jealousy which moved
Ombra, which arose partly from want of confidence in herself, and partly
from ignorance of others, could never have arisen in her cousin. Kate did
not think of comparing herself with any one, or dwelling upon the superior
attractions of another. If people did not care for her, why, they did not care
for her, and there was an end of it; so much the worse for them. To be sure
she never yet had been subjected to the temptation which had made Ombra
so unhappy. The possibility of anything of the kind had never entered her
thoughts. She was eighteen and a half, and had lived for years on terms of
sisterly amity with all the Eldridges, Hardwicks, and the ‘neighbours’
generally; but as yet she had never had a lover, so far as she was aware.
‘The boys,’ as she called them, were all as yet the same to Kate—she liked
some more than others, as she liked some girls more than others; but to be
unhappy or even annoyed because one or another devoted himself to Ombra
more than to her, such an idea had never crossed the girl’s mind. She was
fancy free; but it did not occur to her to make any pious resolution on the
subject, or to decide beforehand that she would obliterate herself in a
corner, in order to give the first place and all the triumph to Ombra. There
are young saints capable of doing this; but Kate Courtenay was not one of
them. Her eyes shone; her rose-lips parted with just the lightest breath of
excitement. She wanted her share of the triumphs too.
Ombra shook her head, but made no reply. ‘Oh,’ she said, to herself,
‘what a hard fate to be always the shadow!’ She exerted all the imagination
she possessed, and threw herself forward, as it were, into the evening which
was coming. Kate was in all the splendour of her first bloom—that radiance
of youth and freshness which is often the least elevated kind of beauty, yet
almost always the most irresistible. The liquid brightness of her eyes, the
wild-rose bloom of her complexion, the exquisite softness, downiness,
deliciousness of cheek and throat and forehead, might be all as evanescent
as the dew upon the sunny grass, or the down on a peach. It was youth—
youth supreme and perfect in its most delicate fulness, the beauté de diable,
as our neighbours call it. Ombra, being still so young herself, did not
characterise it so; nor, indeed, was she aware of this glory of freshness
which, at the present moment, was Kate’s crowning charm. But she
wondered at her cousin’s beauty, and she did not realise her own, which was
so different. ‘Shall I be jealous—shall I hate her?’ she asked herself. At
home she had hated her for a moment now and then. Would it be the same
again?—was her own mind so mean, her character so low, as that? Thinking
well of one’s self, or thinking ill of one’s self, requires only a beginning;
and Ombra’s experience had not increased her respect for her own nature.
Thus she prepared for the Ambassadress’s ball.
It was a strange manner of preparation, the reader will think. Our
sympathy has been trained to accompany those who go into battle without a
misgiving—who, whatever jesting alarm they may express, are never really
afraid of running away; but, after all, the man who marches forward with a
terrible dread in his mind that when the moment comes he will fail, ought to
be as interesting, and certainly makes a much greater claim upon our
compassion, than he who is tolerably sure of his nerves and courage. The
battle of the ball was to Ombra as great an event as Alma or Inkermann. She
had never undergone quite the same kind of peril before, and she was afraid
as to how she should acquit herself. She represented to herself all the
meanness, misery, contemptibleness, of what she supposed to be her
besetting sin—that did not require much trouble. She summed it all up,
feeling humiliated to the very heart by the sense that under other
circumstances she had yielded to that temptation before, and she asked
herself—shall I fail again? She was afraid of herself. She had strung her
nerves, and set her soul firmly for this struggle, but she was not sure of
success. At the last moment, when the danger was close to her, she felt as if
she must fail.
CHAPTER XXXVI.
Kate thought she had never imagined anything so stately, so beautiful, so
gay, so like a place for princes and princesses to meet, as the suite of rooms
in the Palazzo occupied by the English Embassy, where the ball was held.
The vista which stretched before her, one room within another, the lines of
light infinitely reflected by the great mirrors—the lofty splendid rooms, rich
in gold and velvet; the jewels of the ladies, the glow of uniforms and
decorations; the beautiful dresses—all moved her to interest and delight.
Delight was the first feeling; and then there came the strangest sensation of
insignificance, which was not pleasant to Kate. For three years she had
lived in little cottage rooms, in limited space, with very simple
surroundings. But the first glance at this new scene brought suddenly before
the girl’s eyes her native dwelling-place, her own home, which, of course,
was but an English country-house, yet was more akin to the size and
splendour of the Palazzo than to the apartments on the Lung-Arno, or the
little Cottage on the Undercliff. Kate found herself, in spite of herself,
making calculations how the rooms at Langton-Courtenay would look in
comparison; and from that she went on to consider whether any one here
knew of Langton-Courtenay, or was aware that she herself was anything but
Mrs. Anderson’s niece. She was ashamed of herself for the thought, and yet
it went quick as lightning through her excited mind.
Lady Granton smiled graciously upon them, and even shook hands with
the lady whom she knew as Mrs. Vice-Consul, with more cordiality than
usual, with a gratitude which would have given Mrs. Anderson little
satisfaction had she known it, to the woman who had already amused her so
much; but then the group passed on like the other groups, a mother and two
unusually pretty daughters, as people thought, but strangers, nobodies,
looking a little gauche, and out of place, in the fine rooms, where they were
known to no one. Ombra knew what the feeling was of old, and was not
affronted by it; but Kate had never been deprived of a certain shadow of
distinction among her peers. The people at Shanklin had, to their own
consciousness, treated her just as they would have done any niece of Mrs.
Anderson’s; but, unconsciously to themselves, the fact that she was Miss
Courtenay, of Langton-Courtenay, had produced a certain effect upon them.
No doubt Kate’s active and lively character had a great deal to do with it,
but the fact of her heiress-ship, her future elevation, had much to do with it
also. A certain pre-eminence had been tacitly allowed to her; a certain
freedom of opinion, and even of movement, had been permitted, and felt to
be natural. She was the natural leader in half the pastimes going, referred to
and consulted by her companions. This had been her lot for these three
years past. She never had a chance of learning that lesson of personal
insignificance which is supposed to be so salutary. All at once, in a moment,
she learned it now. Nobody looked up to her, nobody considered her,
nobody knew or cared who she was. For the first half-hour Kate was
astonished, in spite of all her philosophy, and then she tried to persuade
herself that she was amused. But the greatest effort could not persuade her
that she liked it. It made her tingle all over with the most curious mixture of
pain, and irritation, and nervous excitement. The dancing was going on
merrily, and there was a hum of talking and soft laughter all around; people
passing and repassing, greeting each other, shaking hands, introducing to
each other their common friends. But the three ladies who knew nobody
stood by themselves, and felt anything but happy.
‘If this is what you call a ball, I should much rather have been at home,’
said Kate, with indignation.
‘It is not cheerful, is it?’ said Ombra. ‘But we must put up with it till we
see somebody we know. I wish only we could find a seat for mamma.’
‘Oh! never mind me, my dear,’ said Mrs. Anderson. ‘I can stand very
well, and it is amusing to watch the people. Lady Barker will come to us as
soon as she sees us.’
‘Lady Barker! As if any one cared for her!’ said Kate; but even Kate,
though she could have cried for mortification, kept looking out very sharply
for Lady Barker. She was not a great lady, nor of any importance, so far as
she herself was concerned, but she held the keys of the dance, of pleasure,
and amusement, and success, for that night, at least, for both Ombra and
Kate. The two stood and looked on while the pairs of dancers streamed past
them, with the strangest feelings—or at least Kate’s feelings were very
strange. Ombra had been prepared for it, and took it more calmly. She
pointed out the pretty faces, the pretty dresses to her cousin, by way of
amusing her.
‘What do you think of this toilette?’ she said. ‘Look, Kate, what a
splendid dark girl, and how well that maize becomes her! I think she is a
Roman princess. Look at her diamonds. Don’t you like to see diamonds,
Kate?’
‘Yes,’ said Kate, with a laugh at herself, ‘they are very pretty; but I
thought we came to dance, not to look at the people. Let us have a dance,
you and I together, Ombra—why shouldn’t we? If men won’t ask us, we
can’t help that—but I must dance.’
‘Oh! hush, my darling,’ said Mrs. Anderson, alarmed. ‘You must not
really think of anything so extraordinary. Two girls together! It was all very
well at Shanklin. Try to amuse yourself for a little, looking at the people.
There are some of the great Italian nobility here. You can recognise them by
their jewels. That is one, for instance, that lady in velvet——’
‘It is very interesting, no doubt,’ cried Kate, ‘and if they were in a
picture, or on a stage, I should like to look at them; but it is very queer to
come to a ball only to see the people. Why, we might be their maids,
standing in a corner to see the ladies pass. Is it right for the lady of the
house to ask us, and then leave us like this? Do you call that hospitality? If
this was Langton-Courtenay,’ said Kate, bringing her own dignity forward
unconsciously, for the first time for years, ‘and it was I who was giving this
ball, I should be ashamed of myself. Am I speaking loud? I am sure I did
not mean it; but I should be ashamed——’
‘Oh! hush, dear, hush!’ cried Mrs. Anderson. ‘Lady Barker will be
coming presently.’
‘But it was Lady Granton who invited us, auntie. It is her business to see
——’
‘Hush, my dearest child! How could she, with all these people to attend
to? When you are mistress of Langton-Courtenay, and give balls yourself,
you will find out how difficult it is——’
‘Langton-Courtenay?’ said some one near. The three ladies
instantaneously roused up out of their languor at the sound. Whose voice
was it? It came through the throng, as if some one half buried in the crowd
had caught up the name, and flung it on to some one else. Mrs. Anderson
looked in one direction, Kate, all glowing and smiling, in another, while the
dull red flush of old, the sign of surprised excitement and passion, came
back suddenly to Ombra’s face. Though they had not been aware of it, the
little group had already been the object of considerable observation; for the
girls were exceptionally pretty, in their different styles, and they were quite
new, unknown, and piquant in their obvious strangeness. Even Kate’s
indignation had been noted by a quick-witted English lady, with an
eyeglass, who was surrounded by a little court. This lady was slightly
beyond the age for dancing, or, if not really so, had been wise enough to
meet her fate half-way, and to retire gracefully from youth, before youth
abandoned her. She had taken up her place, resisting all solicitations.
‘Don’t ask me—my dancing-days are over. Ask that pretty girl yonder,
who is longing to begin,’ she had said, with a smile, to one of her attendants
half an hour before.
‘Je ne demande pas mieux, if indeed you are determined,’ said he. ‘But
who is she? I don’t know them.’
‘Nobody seems to know them,’ said Lady Caryisfort; and so the
observation began.
Lady Caryisfort was very popular. She was a widow, well off, childless,
good-looking, and determined, people said, never to marry again. She was
the most independent of women, openly declaring, on all hands, that she
wanted no assistance to get through life, but was quite able to take care of
herself. And the consequence was that everybody about was most anxious
to assist in taking care of her. All sorts of people took all sorts of trouble to
help her in doing what she never hesitated to say she could do quite well
without them. She was something of a philosopher, and a good deal of a
cynic, as such people often are.
‘You would not be so good to me if I had any need of you,’ she said,
habitually; and this was understood to be ‘Lady Caryisfort’s way.’
‘Nobody knows them,’ she added, looking at the party through her
eyeglass. ‘Poor souls, I daresay they thought it was very fine and delightful
to come to Lady Granton’s ball. And if they had scores of friends already,
scores more would turn up on all sides. But because they know nobody,
nobody will take the trouble to know them. The younger one is perfectly
radiant. That is what I call the perfection of bloom. Look at her—she is a
real rosebud! Now, what fainéants you all are!’
‘Why are we fainéants?’ said one of the court.
‘Well,’ said Lady Caryisfort, who professed to be a man-hater, within
certain limits, ‘I am aware that the nicest girl in the world, if she were not
pretty, might stand there all the night, and nobody but a woman would ever
think of trying to get any amusement for her. But there is what you are
capable of admiring—there is beauty, absolute beauty; none of your washy
imitations, but real, undeniable loveliness. And there you stand and gape,
and among a hundred of you she does not find one partner. Oh! what it is to
be a man! Why, my pet retriever, who is fond of pretty people, would have
found her out by this, and made friends with her, and here are half a dozen
of you fluttering about me!’
There was a general laugh, as at a very good joke; and some one
ventured to suggest that the flutterers round Lady Caryisfort could give a
very good reason——
‘Yes,’ said that lady, fanning herself tranquilly, ‘because I don’t want
you. In society that is the best of reasons; and that pretty creature there does
want you, therefore she is left to herself. She is getting indignant. Why, she
grows prettier and prettier. I wonder those glances don’t set fire to
something! Delicious! She wants her sister to dance with her. What a
charming girl! And the sister is pretty, too, but knows better. And mamma—
oh! how horrified mamma is! This is best of all!’
Thus Lady Caryisfort smiled and applauded, and her attendants laughed
and listened. But, curiously enough, though she was so interested in Kate,
and so indignant at the neglect to which she was subjected, it did not occur
to her to take the young stranger under her protection, as she might so easily
have done. It was her way to look on—to interfere was quite a different
matter.
‘Now this is getting quite dramatic,’ she cried; ‘they have seen some one
they know—where is he?—or even where is she?—for any one they know
would be a godsend to them. How do you do, Mr. Eldridge? How late you
are! But please don’t stand between me and my young lady. I am excited
about her; they have not found him yet—and how eager she looks! Mr.
Eldridge—why, good heavens! where has he gone?’
‘Who was it that said Langton-Courtenay?’ cried Kate; ‘it must be some
one who knows the name, and I am sure I know the voice. Did you hear it,
auntie? Langton-Courtenay!—I wonder who it could be?’
A whole minute elapsed before anything more followed. Mrs. Anderson
looked one way, and Kate another. Ombra did not move. If the lively
observer, who had taken so much interest in the strangers, could have seen
the downcast face which Kate’s bright countenance threw into the shade,
her drama would instantly have increased in interest. Ombra stood without
moving a hair’s-breadth—without raising her eyes—without so much as
breathing, one would have said. Under her eyes that line of hot colour had
flushed in a moment, giving to her face the look of something suppressed
and concealed. The others wondered who it was, but Ombra knew by
instinct who had come to disturb their quiet once more. She recognised the
voice, though neither of her companions did; and if there had not been any
evidence so clear as that voice—had it been a mere shadow, an echo—she
would have known. It was she who distinguished in the ever-moving, ever-
rustling throng, the one particular movement which indicated that some one
was making his way towards them. She knew he—they—were there,
without raising her eyes, before Kate’s cry of joyful surprise informed her.
‘Oh, the Berties!—I beg your pardon—Mr. Hardwick and Mr. Eldridge.
Oh, fancy!—that you should be here!’
Ombra neither fell nor fainted, nor did she even speak. The room swam
round and round, and then came back to its place; and she looked up, and
smiled, and put out her hand.
The two pretty strangers stood in the corner no longer; they stood up in
the next dance, Kate in such a glow of delight and radiance that the whole
ball-room thrilled with admiration. There had been a little hesitation as to
which of the two should be her partner—a pause during which the two
young men consulted each other by a look; but she had herself so clearly
indicated which Bertie she preferred, that the matter was speedily decided.
‘I wanted to have you,’ she said frankly to Bertie Hardwick, as he led her
off, ‘because I want to hear all about home. Tell me about home. I have not
thought of Langton for two years at least, and my mind is full of it to-night
—I am sure I don’t know why. I keep thinking, if I ever give a ball at
Langton, how much better I will manage it. Fancy!’ cried Kale, flushing
with indignation, ‘we have been here an hour, and no one has asked us to
dance, neither Ombra nor me.’
‘That must have been because nobody knew you,’ said Bertie Hardwick.
‘And whose fault was that? Fancy asking two girls to a dance, and then
never taking the trouble to look whether they had partners or not! If I ever
give a ball, I shall behave differently, you may be sure.’
‘I hope you will give a great many balls, and that I shall be there to see.’
‘Of course,’ said Kate, calmly; ‘but if you ever see me neglecting my
duty like Lady Granton, don’t forget to remind me of to-night.’
Lady Granton’s sister was standing next to her, and, of course, heard
what she said.
CHAPTER XXXVII.
‘It was you who knew them, Mr. Eldridge,’ said Lady Caryisfort. ‘Tell me
about them—you can’t think how interested I am. She thinks Lady Granton
neglected her duty, and she means to behave very differently when she is in
the same position. She is delicious! Tell me who she is.’
‘My cousin knows better than I do,’ said Bertie Eldridge, drawing back a
step. ‘She is an old friend and neighbour of his.’
‘If your cousin were my son, I should be frightened of so very dangerous
a neighbour,’ said Lady Caryisfort. It was one of her ways to distinguish as
her possible sons men a few years younger than herself.
‘Even to think her dangerous would be a presumption in me,’ said Bertie
Hardwick. ‘She is the great lady at home. Perhaps, though you laugh, you
may some day see whether she can keep the resolution to behave
differently. She is Miss Courtenay, of Langton-Courtenay, Lady Caryisfort.
You must know her well enough by name.’
‘What!—the Vice-Consul’s niece! I must go and tell Lady Granton,’ said
an attaché, who was among Lady Caryisfort’s attendants.
She followed him with her eyes as he went away, with an amused look.
‘Now my little friend will have plenty of partners,’ she said. ‘Oh! you
men, who have not even courage enough to ask a pretty girl to dance until
you have a certificate of her position. But I don’t mean you two. You had
the certificate, I suppose, a long time ago?’
‘Yes. She has grown very pretty,’ said Bertie Eldridge, in a patronising
tone.
‘How kind of you to think so!—how good of you to make her dance! as
the French say. Mr. Hardwick, I suppose she is your father’s squire? Are
you as condescending as your cousin? Give me your arm, please, and
introduce me to the party. I am sure they must be fun. I have heard of Mrs.
Vice-Consul——’
‘I don’t think they are particularly funny,’ said Bertie Hardwick, with a
tone which the lady’s ear was far too quick to lose.
‘Ah!’ she said to herself, ‘a victim!’ and was on the alert at once.
‘It is the younger one who is Miss Courtenay, I suppose?’ she said. ‘The
other is—her cousin. I see now. And I assure you, Mr. Hardwick, though
she is not (I suppose?) an heiress, she is very pretty too.’
Bertie assented with a peculiar smile. It was a great distinction to Bertie
Hardwick to be seen with Lady Caryisfort on his arm, and a very great
compliment to Mrs. Anderson that so great a personage should leave her
seat in order to make her acquaintance. Yet there were drawbacks to this
advantage; for Lady Caryisfort had a way of making her own theories on
most things that fell under her observation; and she did so at once in respect
to the group so suddenly brought under her observation. She paid Mrs.
Anderson a great many compliments upon her two girls.
‘I hear from Mr. Hardwick that I ought to know your niece “at home,” as
the schoolboys say,’ she said. ‘Caryisfort is not more than a dozen miles
from Langton-Courtenay. I certainly did not expect to meet my young
neighbour here.’
‘Her uncle wishes her to travel; she is herself fond of moving about,’
murmured Mrs. Anderson.
‘Oh! to be sure—it is quite natural,’ said Lady Caryisfort; ‘but I should
have thought Lady Granton would have known who her guest was—and—
and all of us. There are so many English people always here, and it is so
hard to tell who is who——’
‘If you will pardon me,’ said Mrs. Anderson, who was not without a
sense of her own dignity, ‘it is just because of the difficulty in telling who is
who that I have brought Kate here. Her guardian does not wish her to be
introduced in England till she is of age; and as I am anxious not to attract
any special attention, such as her position might warrant——’
‘Is her guardian romantic?’ said Lady Caryisfort. ‘Does he want her to
be loved for herself alone, and that sort of thing? For otherwise, do you
know, I should think it was dangerous. A pretty girl is never quite safe——’
‘Of course,’ said Mrs. Anderson, gravely, ‘there are some risks, which
one is obliged to run—with every girl.’
And she glanced at Bertie Hardwick, who was standing by; and either
Bertie blushed, being an ingenuous young man, or Lady Caryisfort fancied
he did; for she was very busy making her little version of this story, and
every circumstance, as far as she had gone, fitted in.
‘But an heiress is so much more dangerous than any other girl. Suppose
she should fancy some one beneath—some one not quite sufficiently—
some one, in short, whom her guardians would not approve of? Do you
know, I think it is a dreadful responsibility for you.’
Mrs. Anderson smiled; but she gave her adviser a sudden look of fright
and partial irritation.
‘I must take my chance with others,’ she said. ‘We can only hope nothing
will happen.’
‘Nothing happen! When it is girls and boys that are in question
something always happens!’ cried Lady Caryisfort, elevating her eyebrows.
‘But here come your two girls, looking very happy. Will you introduce them
to me, please? I hope you will not be affronted with me for an inquisitive
old woman,’ she went on, with her most gracious smile; ‘but I have been
watching you for ever so long.’
She was watching them now, closely, scientifically, under her drooped
eyelids. Bertie had brightened so at their approach, there could be no
mistaking that symptom. And the pale girl, the dark girl, the quiet one, who,
now that she had time to examine her, proved almost more interesting than
the beauty—had changed, too, lighting up like a sky at sunset. The red line
had gone from under Ombra’s eyes; there was a rose-tint on her cheek
which came and went; her eyes were dewy, like the first stars that come out
at evening. A pretty, pensive creature, but bright for the moment, as was the
other one—the one who was all made of colour and light.
‘This is my niece, Lady Caryisfort,’ said Mrs. Anderson, with an effort;
and she added, in a lower tone, ‘This is Ombra, my own child.’
‘Do you call her Ombra? What a pretty name! and how appropriate!
Then of course the other one is sunshine,’ said Lady Caryisfort. ‘I hope I
shall see something of them while I stay here; and, young ladies, I hope, as
I said, that you do not consider me a very impertinent old woman because I
have been watching you.’
Kate laughed out the clearest, youthful laugh.
‘Are you an old woman?’ she said. ‘I should not have guessed it.’
Lady Caryisfort turned towards Kate with growing favour. How subtle is
the effect of wealth and greatness (she thought). Kate spoke out frankly, in
the confidence of her own natural elevation, which placed her on a level
with all these princesses and great ladies; while Ombra, though she was