100% found this document useful (4 votes)
58 views

Instant download JavaScript Unit Testing 1st Edition Hazem Saleh pdf all chapter

JavaScript

Uploaded by

mehlenxetai30
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
58 views

Instant download JavaScript Unit Testing 1st Edition Hazem Saleh pdf all chapter

JavaScript

Uploaded by

mehlenxetai30
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Download Full ebookname - Read Now at ebookname.

com

JavaScript Unit Testing 1st Edition Hazem Saleh

https://ebookname.com/product/javascript-unit-testing-1st-
edition-hazem-saleh/

OR CLICK BUTTON

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Jasmine JavaScript Testing Leverage the power of unit


testing to create bigger and better JavaScript
applications 1st Edition Paulo Ragonha
https://ebookname.com/product/jasmine-javascript-testing-leverage-the-
power-of-unit-testing-to-create-bigger-and-better-javascript-
applications-1st-edition-paulo-ragonha/
ebookname.com

Pro JSF and HTML5 Building Rich Internet Components 2nd


Edition Hazem Saleh

https://ebookname.com/product/pro-jsf-and-html5-building-rich-
internet-components-2nd-edition-hazem-saleh/

ebookname.com

Pragmatic unit testing in Java with JUnit 1st Edition Andy


Hunt

https://ebookname.com/product/pragmatic-unit-testing-in-java-with-
junit-1st-edition-andy-hunt/

ebookname.com

Modern Economic Thought Sidney Weintraub (Editor)

https://ebookname.com/product/modern-economic-thought-sidney-
weintraub-editor/

ebookname.com
Teach Yourself VISUALLY Dreamweaver CS4 1st Edition Janine
C. Warner

https://ebookname.com/product/teach-yourself-visually-dreamweaver-
cs4-1st-edition-janine-c-warner/

ebookname.com

Duchess of Palms A Memoir 1st Edition Nadine Eckhardt

https://ebookname.com/product/duchess-of-palms-a-memoir-1st-edition-
nadine-eckhardt/

ebookname.com

This Bright Light of Ours Stories from the Voting Rights


Fight 1st Edition Maria Gitin

https://ebookname.com/product/this-bright-light-of-ours-stories-from-
the-voting-rights-fight-1st-edition-maria-gitin/

ebookname.com

Shakespeare for students critical interpretations of


Shakespeare s plays and poetry 2nd ed Edition Anne Marie
Hacht
https://ebookname.com/product/shakespeare-for-students-critical-
interpretations-of-shakespeare-s-plays-and-poetry-2nd-ed-edition-anne-
marie-hacht/
ebookname.com

Implementing the IBM Rational Unified Process and


Solutions A Guide to Improving Your Software Development
Capability and Maturity 1st Edition Joshua Barnes
https://ebookname.com/product/implementing-the-ibm-rational-unified-
process-and-solutions-a-guide-to-improving-your-software-development-
capability-and-maturity-1st-edition-joshua-barnes/
ebookname.com
Key words for fluency intermediate collocation practice
learning and practising the most useful words of English
1st Edition George Woolard
https://ebookname.com/product/key-words-for-fluency-intermediate-
collocation-practice-learning-and-practising-the-most-useful-words-of-
english-1st-edition-george-woolard/
ebookname.com
www.it-ebooks.info
JavaScript Unit Testing

Your comprehensive and practical guide to efficiently


performing and automating JavaScript unit testing

Hazem Saleh

BIRMINGHAM - MUMBAI

www.it-ebooks.info
JavaScript Unit Testing

Copyright © 2013 Packt Publishing

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

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

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

First published: January 2013

Production Reference: 1040113

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham B3 2PB, UK.

ISBN 978-1-78216-062-5

www.packtpub.com

Cover Image by Jasmine Doremus (jasdoremus@gmail.com)

www.it-ebooks.info
Credits

Author Project Coordinator


Hazem Saleh Priya Sharma

Reviewer Proofreaders
Allan Lykke Christensen Lawrence A. Herman
Joel Johnson
Acquisition Editor
Jonathan Titmus Indexer
Hemangini Bari
Commissioning Editors
Harsha Bharwani Graphics
Priyanka Shah Aditi Gajjar

Technical Editors Production Coordinator


Hardik Soni Melwyn D'sa
Devdutt Kulkarni
Cover Work
Copy Editors Melwyn D'sa
Brandt D'Mello
Insiya Morbiwala
Alfida Paiva

www.it-ebooks.info
About the Author

Hazem Saleh has 9 years of experience in JEE and open source technologies.
He has worked as a technical consultant for different clients in Europe (Sweden),
North America (USA, Canada), South America (Peru), Africa (Egypt), and Asia
(Qatar, Kuwait). He is an Apache MyFaces committer, and the founder of many
open source projects.

Besides being the co-author of the book The Definitive Guide to Apache MyFaces
and Facelets, Zubin Wadia, Martin Marinschek, Hazem Saleh, Dennis Byrne, Apress
and the author of this book, Hazem is also an author of many technical articles,
a developerWorks contributing author, and a technical speaker at both local and
international conferences, such as the IBM Regional Technical Exchange, CONFESS,
and JavaOne. Hazem is now working for IBM Egypt (Cairo Lab SWG Services) as
an Advisory Software Engineer. He is a Web 2.0 subject matter expert and an IBM
Certified Expert IT Specialist.

I would like to thank my mother, my father, my brother Mohamed,


my sister Omnia, and all my family for endlessly supporting me
while writing this book. I would like to thank the love and best
friend of my life, my wife Naglaa, for encouraging and supporting
me while writing this book. I would like to thank all the people who
have done me a favor; I would like to thank Ahmed Fouad, Tamer
Mahfouz, my dearest brothers Ali AlKahki and Amr Ali, and every
one who has done me any kind of favor.

www.it-ebooks.info
About the Reviewer

Allan Lykke Christensen is the Director of Interactive Media Management


and the Vice President of Danish ICT Management, an international consulting
firm with a focus on ICT in developing economies. He is responsible for the daily
management of teams in Uganda, Bangladesh, and Denmark. In his daily work, he is
also responsible for project planning, initiating, and overall implementation. He has
been developing and implementing IT projects for more than 10 years. His expertise
covers a wide range; he has developed workflow systems, information systems,
e-learning tools, knowledge-management systems, and websites. He has worked
as Team Leader on several major European Commission financed ICT projects in
various developing economies. He has co-authored the book The Definitive Guide to
Apache MyFaces and Facelets, Apress, and made countless presentations and training
sessions on programming-related topics around the world. Allan is also the Lead
Developer of the CONVERGE project, which aims at implementing an open source,
editorial content management system for media houses. More information on this
can be found at http://www.getconverge.com.

www.it-ebooks.info
www.PacktPub.com

Support files, eBooks, discount offers


and more
You might want to visit www.PacktPub.com for support files and downloads related to
your book.

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
service@packtpub.com 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.

http://PacktLib.PacktPub.com

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can access, read and search across 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 web browser

Free Access for Packt account holders


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

www.it-ebooks.info
Table of Contents
Preface 1
Chapter 1: Unit Testing JavaScript Applications 7
What unit testing is 7
Why we need unit testing 8
What Test-Driven Development (TDD) is 10
Complexities in testing JavaScript applications 11
Weather forecasting application 13
Exploring the application's HTML and JavaScript code 15
Running the weather application 28
Summary 29
Chapter 2: Jasmine 31
Configuration 31
Writing your first Jasmine test 32
The nested describe blocks 38
Jasmine matchers 39
The toBe matcher 39
The toBeDefined and toBeUndefined matchers 40
The toBeNull matcher 41
The toBeTruthy and toBeFalsy matchers 41
The toContain matcher 42
The toBeLessThan and toBeGreaterThan matchers 42
The toMatch matcher 43
Developing custom Jasmine matchers 43
Testing asynchronous (Ajax) JavaScript code 45
The runs() function 45
The waits() function 46
The waitsFor() function 47
The spyOn() function 49

www.it-ebooks.info
Table of Contents

HTML fixtures 51
Configuring the jasmine-jquery plugin 52
The loadFixtures module 53
Testing the weather application 55
Testing the LoginClient object 56
Testing the RegistrationClient object 59
Testing the WeatherClient object 63
Running the weather application tests 63
Summary 63
Chapter 3: YUI Test 65
Writing your first YUI test 67
Assertions 74
The assert assertion 74
The areEqual and areNotEqual assertions 75
The areSame and areNotSame assertions 75
The datatype assertions 75
Special value assertions 76
The fail assertion 77
Testing asynchronous (Ajax) JavaScript code 78
The wait and resume functions 78
Testing the weather application 79
Testing the LoginClient object 80
Testing the RegistrationClient object 84
Testing the WeatherClient object 88
Running the weather application tests 89
Generating test reports 89
Automation and integration with build management tools 95
Configuring YUI Test Selenium Driver 95
Using YUI Test Selenium Driver in the weather application 96
Integration with build management tools 98
Summary 99
Chapter 4: QUnit 101
Configuration 101
Writing your first QUnit test 102
Assertions 108
The ok assertion 108
The equal and notEqual assertions 109
The deepEqual and notDeepEqual assertions 109
The expect assertion 110
Developing custom QUnit assertions 111

[ ii ]

www.it-ebooks.info
Table of Contents

Testing asynchronous (Ajax) JavaScript code 114


The stop and start APIs 114
Testing the weather application 116
Testing the LoginClient object 118
Testing the RegistrationClient object 121
Testing the WeatherClient object 126
Running the weather application tests 128
Summary 129
Chapter 5: JsTestDriver 131
Architecture 131
Configuration 132
Writing your first JSTD test 134
Assertions 139
The assert, assertTrue, and assertFalse([msg], expression) assertions 140
The assertEquals and assertNotEquals([msg], expected, actual)
assertions 140
The assertSame and assertNotSame([msg], expected, actual)
assertions 140
The datatype assertions 141
Special value assertions 142
The fail([msg]) assertion 143
Testing asynchronous (Ajax) JavaScript code 143
AsyncTestCase, queue, and callbacks 144
Testing the weather application 145
Testing the LoginClient object 147
Testing the RegistrationClient object 149
Testing the WeatherClient object 153
Configuring the proxy 153
Running the weather application tests 154
Generating test reports 155
Integration with other JavaScript test frameworks 160
Integrating JSTD with Jasmine 162
Integrating JSTD with QUnit 164
Integration with build management tools 167
Integration with the IDEs 167
Eclipse integration 168
Summary 170
Index 171

[ iii ]

www.it-ebooks.info
www.it-ebooks.info
Preface
One of the biggest challenges of many web applications is being supported
by different browsers with different versions. JavaScript code that runs on
the Safari browser will not necessarily run correctly on Internet Explorer (IE),
Firefox, or Google chrome browsers. This challenge is caused by the lack of unit
testing of the JavaScript code that has lived in the web application from day one.
Without unit testing the JavaScript code, more money will have to be spent for
testing and retesting the application's web pages after deciding to upgrade to
current, supported browsers (or after updating the JavaScript code of the web
pages with non-trivial features).

The JavaScript Unit Testing book is a comprehensive practical guide that illustrates
in detail how to efficiently create and automate JavaScript tests for web applications
using popular, JavaScript unit testing frameworks, such as Jasmine, YUI Test, QUnit,
and JsTestDriver.

This book explains the concept of JavaScript unit testing and explores the bits of an
interactive Ajax web application (the weather application). Throughout the book,
the JavaScript part of the weather application is tested using different JavaScript unit
testing frameworks. The book illustrates how to generate test and code coverage
reports of developed JavaScript tests. It also explains how to automate the running of
JavaScript tests from build and continuous integration tools. The book shows how to
integrate different JavaScript unit testing frameworks with each other in order to test
web applications in the most efficient way.

www.it-ebooks.info
Preface

What this book covers


Chapter 1, Unit Testing JavaScript Applications, helps you understand what unit
testing is, the requirements of a good unit test, and why unit testing is needed.
You will also learn the difference between Test-Driven Development and traditional
unit testing. You will understand the complexities of testing JavaScript code, and
the requirements of good, JavaScript unit testing tools. In this chapter, we will
explore the weather web application's JavaScript section which we will unit test
in the next chapters.

Chapter 2, Jasmine, helps you learn what Jasmine is and how to use it for testing
synchronous JavaScript code. You will learn how to test asynchronous (Ajax)
JavaScript code using the Jasmine Spies, waitsFor, and runs mechanisms. You will
learn how to perform mock Ajax testing using Jasmine. You will learn about the
various matchers provided by the framework, and how to load HTML fixtures in
your Jasmine tests. In this chapter, you will learn how to use Jasmine for testing the
weather application's JavaScript section.

Chapter 3, YUI Test, helps you to learn what YUI Test is and how to use this
JavaScript unit testing framework for testing synchronous JavaScript code. You will
learn how to test asynchronous (Ajax) JavaScript code using the YUI Test's wait and
resume mechanisms. You will learn about the various assertions provided by the
framework, how to display XML and JSON test reports using framework reporter
APIs, and how to generate test reports automatically using the YUI Test Selenium
Driver. You will learn how to automate running YUI tests using the YUI Test
Selenium Driver, and how to integrate an automation script with build management
and continuous integration tools. In this chapter, you will learn how to use YUI Test
for testing the weather application's JavaScript section.

Chapter 4, QUnit, helps you to understand what QUnit is and how to use it for
testing synchronous JavaScript code. You will learn how to test asynchronous
(Ajax) JavaScript code using the QUnit test mechanism and the QUnit asyncTest
mechanism. You will also learn the different assertions provided by the framework,
and how to develop your own assertion in order to simplify your test code. You will
learn how to load HTML fixtures in your QUnit tests. In this chapter, you will learn
how to use the framework for testing the weather application's JavaScript section.

Chapter 5, JsTestDriver, helps you to learn what JsTestDriver (JSTD) is, the JSTD
architecture, the JSTD configuration, and how to use JSTD for testing synchronous
JavaScript code. You will learn how to test asynchronous (Ajax) JavaScript code
using the JSTD AsyncTestCase object. You will learn the various assertions provided
by the framework, and how to generate test and code coverage reports using the
framework's code coverage plugin. You will learn how to use JSTD as a test runner
for the other JavaScript unit testing frameworks mentioned in the book, such as

[2]

www.it-ebooks.info
Preface

Jasmine and QUnit, in order to enable the execution of the tests of these frameworks
from the command-line interface. You will learn how to integrate the tests of
JSTD (and the tests of the JavaScript frameworks on top of JSTD) with build and
continuous integration tools. You will learn how to work with the JSTD framework
in one of the most popular integrated development environments (IDEs) which
is Eclipse. In this chapter, you will learn how to use JSTD for testing the weather
application's JavaScript section.

What you need for this book


You will need the following software in order to run all of the examples in this book:

• Apache Tomcat 6, which can be found at http://tomcat.apache.org/


download-60.cgi
• Java Development Kit (JDK) Version 5.0 or later, which can be found at
http://www.oracle.com/technetwork/java/javase/downloads/index.
html
• The Selenium Server version 2.25.0 (for Chapter 3, YUI Test only), which can
be found at http://seleniumhq.org/download/
• Eclipse IDE (for Chapter 5, JsTestDriver only), which can be found at
http://www.eclipse.org/downloads/packages/release/indigo/sr2

Who this book is for


The target audience for this book is developers, designers, and architects of
web applications.

Conventions
In this book, you will find a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.

Code words in text are shown as follows: "The validateLoginForm function


calls the LoginClient JavaScript object, which is responsible for validating the
login form."

A block of code is set as follows:


function validateLoginForm() {
var loginClient = new weatherapp.LoginClient();

[3]

www.it-ebooks.info
Preface

var loginForm = {
"userNameField" : "username",
"passwordField" : "password",
"userNameMessage" : "usernameMessage",
"passwordMessage" : "passwordMessage"
};

return loginClient.validateLoginForm(loginForm);
}

When we wish to draw your attention to a particular part of a code block,


the relevant lines or items are set in bold:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit test runner</title>
<link rel="stylesheet" href="lib/qunit-1.10.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="lib/qunit-1.10.0.js"></script>

...The test code here...


</body>
</html>

Any command line input or output is written as follows:


java -jar JsTestDriver-1.3.4.b.jar --port 9876 --browser [firefoxpath],
[iepath],[chromepath]

New terms and important words are shown in bold. Words that you see on the
screen, in menus or dialog boxes, for example, appear in the text like this: "In this
application, the user enters his/her name and then clicks on the Welcome button."

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

[4]

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 may have disliked. Reader feedback is important for
us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to feedback@packtpub.com,


and mention the book title via the subject of your message.

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.

Downloading the example code


You can download the example code files for all Packt books you have purchased
from your account at http://www.PacktPub.com. If you purchased this book
elsewhere, you can visit http://www.PacktPub.com/support and register to have
the files e-mailed directly to you.

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 would 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/support, 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 on our website, or added to any list
of existing errata, under the Errata section of that title. Any existing errata can be
viewed by selecting your title from http://www.packtpub.com/support.

[5]

www.it-ebooks.info
Preface

Piracy
Piracy of copyright 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.

Please contact us at copyright@packtpub.com with a link to the suspected


pirated material.

We appreciate your help in protecting our authors, and our ability to bring you
valuable content.

Questions
You can contact us at questions@packtpub.com if you are having a problem with
any aspect of the book, and we will do our best to address it.

[6]

www.it-ebooks.info
Unit Testing JavaScript
Applications
Before going into the details of unit testing JavaScript applications, we need to
understand first what unit testing is and why we need to unit test our applications.
This chapter also shows the complexities of testing JavaScript applications and
why it is not as simple as desktop applications. Finally, the chapter illustrates the
functionality and the JavaScript code of a sample weather application. We will unit
test its JavaScript code in the following chapters of the book.

What unit testing is


Unit testing is not a new concept in the software development world. Thanks to Kent
Beck, the concept of unit testing was introduced in Smalltalk, then the concept was
transferred to many other programming languages, such as C, C++, and Java. The
classical definition of unit testing is that it is a piece of code (usually a method) that
invokes another piece of code and later checks the correctness of some assumptions.

The definition is technically correct; however, it does not show us how to make
a really good unit test. In order to write a good unit test, we need to understand
the requirements of a good unit test.

www.it-ebooks.info
Unit Testing JavaScript Applications

As shown in the following figure, a good unit test should be automated, repeatable,
easy to understand, incremental, easy to run, and fast.

A good unit test should be automated and repeatable, which means that other
team members can repeat running the application unit tests for every significant
code change automatically. It should also be easy to understand so that other team
members can understand what your test means and can continue adding more test
cases or updating an existing test case. A good unit test should be incremental; this
means that the unit test should be updated if a new relevant defect is detected in the
code, which means that this defect will not happen again as long as this unit test is
running periodically. Finally, a good unit test should be easy to run; it should run
by executing a command or by clicking a button and should not take a long time
for execution because fast unit tests can help in increasing the development
team's productivity.

So let's go back to the definition and refine it. Unit testing is a piece of code
(usually a method) that invokes another piece of code and checks the correctness
of some assumptions later. Unit testing should be automated, repeatable, easy to
understand, incremental, easy to run, and fast.

Why we need unit testing


Unit testing applications is not something nice to have. It is actually a mandatory
activity for having a successful software solutions that can cope with different
changes across time with high stability. There is no excuse to skip unit testing of
applications even for projects with a tight schedule. The importance of unit testing
may not appear in the early stages of the project; however, its advantages are visible
in the middle and the final stages of the project, when the code gets complicated,
more features are required, and more regression defects appear (defects that appear
again after a major code change).

[8]

www.it-ebooks.info
Chapter 1

Without unit testing, the integration of the different components in the system
becomes complicated. This complexity results from the tracing of the defects of not
only the integration between the components but also each "buggy" component. This
complicates the life of the developers by making them spend nights in the office in
order to meet the schedule.

The number of new defects and the regression defects becomes unmanageable when
the code base becomes complicated and unit testing is not available. The developer
can resolve a specific defect and, after a set of code changes, this defect can happen
again because there is no repeatable test case to ensure that the defect will not
happen again.

Having more number of defects per lines of code affects the application's quality
badly, and this means that more time has to be spent on testing the application.
Bad quality applications have a longer test cycle for each project deployment
(or phase), because they have a high probability of having more defects for every
code change, which leads to more pressure on the project management, the project
developers, and the project testers.

Having good unit testing can be a good reference for the system documentation
because it contains the test scenarios of the system use cases. In addition to this,
unit testing shows how the system APIs are used, which reflect the current design
of the system. This means that unit testing is a powerful basis of code and design
refactoring for having more enhancements in the system.

Having good unit testing minimizes the number of regression defects because in good
unit testing the system has a repeatable number of test cases for every relevant defect.
Having a continuous integration job that runs periodically on the application unit tests
will ensure that these defects will not happen again, because if a specific defect appears
again due to a change in the application code, then the developer will be notified to fix
the defect and ensure that the test case of this defect passes successfully.

Continuous integration (CI) is a practice that ensures automating


the build and the test process of the application. In continuous
integration testing, the tests of the application source code run
periodically (for example many times per day) in order to identify
the application's potential problems and to reduce the integration
time of the application components.

As a result of reducing the regression defects, having good unit testing reduces the
test cycle for each phase (or system deployment). In addition to this, the application
can have more and more features per iterations or phases peacefully without
worrying if these features shall break an existing module that has good unit tests.

[9]

www.it-ebooks.info
Unit Testing JavaScript Applications

What Test-Driven Development (TDD) is


There are two known approaches in writing unit tests for applications.
The first approach prefers writing unit tests after writing the actual application code
and this approach is called traditional unit testing. The second approach prefers
writing unit tests before writing the actual application code, and this approach is
called Test-Driven Development (TDD) or the Test-First approach.

As shown in the following figure, traditional unit testing is about writing the
application code first. It can simply be a class or a method. After writing the piece
of code, the unit tests, which test the functionality of the code, are written. Then the
unit tests run. If the unit tests fail then the developer fixes the defects and runs the
unit tests again. If the unit tests succeed then the developer can either refactor the
code and run the tests again or continue to write the next piece of code and so on.

As shown in the following figure, TDD starts by writing a failing unit test to indicate
that the functionality is missing. After writing the unit test, the unit test must be run
to ensure that it fails. After that, the developer writes the application code that meets
the unit test expectation. The unit test must be run again to ensure that it succeeds.
If it fails then the developer fixes the bugs and if it succeeds the developer can either
refactor the application code or continue writing the next test case.

[ 10 ]

www.it-ebooks.info
Chapter 1

TDD is a powerful technique, as it can give you more control on the application code
and design; however, it is a double-edged sword because if it is done incorrectly,
writing the tests can waste a lot of time and the schedule of the project can slip.
Finally, either you are using TDD or traditional unit testing technique. Don't forget
to make your tests automated, repeatable, easy to understand, incremental, easy to
run, and fast.

Complexities in testing JavaScript


applications
Testing JavaScript applications is complex and requires a lot of time and
effort. Testing JavaScript applications requires the tester to test the application
on different browsers (Internet Explorer, Firefox, Safari, Chrome, and so on).
This is because the JavaScript code that runs on a specific browser will not
necessarily work on another browser.

Testing existing JavaScript web applications (with many web pages) on new
browsers that are not supported by the application code is not a flexible process.
Supporting a new unsupported browser means allocating more time for testing the
application again on this new browser and for the new/regression defects to be fixed
by the developers. Let's see a simple Broken JavaScript example, which illustrates
this idea. In this example, the user enters his/her name and then clicks on the
Welcome button. After that the welcome message appears.

[ 11 ]

www.it-ebooks.info
Unit Testing JavaScript Applications

The following code snippet shows the broken JavaScript example:


<!DOCTYPE html>
<html>
<head>
<title>Broken JavaScript Example</title>
<script type=»text/javascript»>
function welcome() {
var userName = document.getElementById(«userName»).value;
document.getElementById(«welcomeMessage»).innerText = «Welcome «
+ userName + «!»;
}
</script>
</head>
<body>
<h1>Broken JavaScript Example</h1>

<label>Please enter your name:</label>


<input id=»userName» type=»text» /><br/>
<input type=»button» onclick=»welcome()» value=»Welcome»></
input><br/><br/>
<div id=»welcomeMessage»/>

</body>
</html>

Downloading the example code


You can download the example code files for all Packt books you have
purchased from your account at http://www.PacktPub.com. If you
purchased this book elsewhere, you can visit http://www.PacktPub.
com/support and register to have the files e-mailed directly to you.

If you run the code shown in the previous code snippet, you will find that it works
fine in Internet Explorer (IE) and Safari while it does not work in Firefox (to be more
specific, this example works on Internet Explorer 8 and Safari 5.1, while it will not
work on Firefox 3.6). The reason behind this problem is that the innerText property
is not supported in Firefox. This is one of the hundreds of examples that show a code
that works in a specific browser while it does not work in another one.

As a result of these complexities, testing JavaScript code requires a good unit


testing tool, which provides mechanisms to overcome these complexities. The good
JavaScript unit testing tool should be able to execute the test cases across all of the
browsers, should have an easy setup, should have an easy configuration, and should
be fast in executing the test cases.

[ 12 ]

www.it-ebooks.info
Chapter 1

Weather forecasting application


Now, let's move to the weather forecasting application. The weather forecasting
application is a Java web application that allows the users to check the current
weather in different cities in the world. The weather forecasting application contains
both synchronous and asynchronous (Ajax) JavaScript code, which we will test in the
later chapters of the book using the different JavaScript unit testing frameworks.

The weather forecasting application mainly contains three use cases:

• Log in to the application


• Register a user in the application
• Check the current weather in a specific city

The weather forecasting application is a Java web application. The server-side part of
the application is written using Java servlets (http://docs.oracle.com/javaee/6/
tutorial/doc/bnafd.html). If you are not familiar with Java servlets, do not
worry. This book focuses only on JavaScript unit testing; all you need to know about
these servlets is the functionality of each one of them, not the code behind it. The
functionality of each application servlet will be explained during when the JavaScript
code is explained, to show you the complete Ajax request life cycle with the server.

Another thing that needs to be mentioned is that the weather application pages
are .jsp files; however, 99 percent of their code is pure HTML code that is easy to
understand (the application pages code will be explained in detail in the next section).

The first screen of the application is the login screen in which the user enters his
username and password, as shown in the following screenshot:

[ 13 ]

www.it-ebooks.info
Unit Testing JavaScript Applications

When the user clicks on the Login button, there is a JavaScript login client that
ensures that the username and the password are entered correctly. If the username
and the password are correct, they are submitted to the server, which validates them
if the user is registered in the application. If the user is registered in the application
then the user is redirected to the weather checking page; otherwise an error message
appears to the user.

The username field must not be empty and has to be in a valid e-mail address format.
The password field also must not be empty and has to contain at least one digit, one
capital, one small character, and at least one special character. The password length
has to be six characters or more.

In the weather checking page, the user can select one of the available cities from the
combobox, then click on the Get weather condition button to get the current weather
information of the selected city, as shown in the following screenshot:

In the user registration page, the user can register in the application by entering
his username and confirmed password, as shown in the following screenshot:

[ 14 ]

www.it-ebooks.info
Random documents with unrelated
content Scribd suggests to you:
in the great heat, from which they sought to shelter their heads
under their neighbours’ bellies, the horses stood, each one with his
plumed and impure rider. “Sometimes,” says the Doctor, “I saw
ravens sitting in the same confidential manner upon the backs of
horses and dromedaries. In North Africa I observed similar intimacy
between kites and cows, ravens and swine. Dr Knoblecher relates
that in the Nile districts of Central Africa he often saw waterfowl,
particularly herons and ibises, sit upon the backs of elephants. Only
to one kind of animal has the Armenian caravan-horse a natural
hatred and strong aversion—namely, to the camel, who, on his side,
detests the horse. Even in caravans composed of both kinds of
beasts, long accustomed to each other’s presence, this antipathy
endures. Horses and camels, if left in any degree to their own free
will, go separately to pasture. Long habit of being together restrains
them from hostile outbreaks, but I never witnessed, during the whole
period of my Oriental travels, an example of even a tolerably good
understanding between them.”
On the 20th of June—so cold a morning, that, in spite of cloak and
mackintosh, Dr Wagner was half-frozen—the caravan reached the
Kourd village of Yendek, and encamped in a narrow valley, the
mountains around which had been reckoned, a few years previously,
amongst the most unsafe in Kourdistan, a caravan seldom passing
unassailed. Towards evening a Kourd chief came into camp. “He
wore no beard, but thick and long moustaches—as formerly the
Janissaries—a huge turban, a short burka, very wide trousers. He
had his horse shod by one of our Armenians, took a fancy to Karapet-
Bedochil’s pocket-knife, and asked him for it as a keepsake. He did
not pay for the shoeing, and rode off, with small thanks, amidst the
courteous greetings of all the Armenians—even of our haughty
Karivan-Baschi. I afterwards laughingly asked the Kadertshi why he
had not demanded payment from the Kourd for the shoes and his
work. ‘Laugh away!’ was his reply; ‘if ever you meet that fellow alone,
you won’t be quite so merry.’ The Kourd, who was armed with
pistols, gun, and sabre, certainly looked the very model of a captain
of banditti.”
Before reaching Persian territory, where the risk from robbers
diminishes, some pack-horses were cleverly stolen by the Kourds;
and two men, who were sent, well mounted, to overtake the thieves
and negotiate for the restoration of the property, returned to camp
despoiled of clothes and steeds. Ultimately, the Pasha of Erzroum
extorted the bales from the Kourds, who are too prudent to drive
things to extremities. But, for the time, Kara Gos had to pursue his
journey minus his merchandise, and greatly cast down at the loss,
which he merited for his griping effrontery, and for the poltroonery
with which, a few days before, he had deviated from his direct road
on the rude demand of some Kourds, who sought to pick a quarrel
with him—a sort of wolf-and-lamb business—for riding through their
pastures. He forgot his loss, however, when reckoning at Tabriz the
full sack of sounding gold tomauns received for carriage of goods;
and in the joy of his heart he even condescended to speak to Dr
Wagner, and to extend to him his forgiveness for having refused to
be imposed upon, so that they parted in amity at last.
Tabriz, in size the second, in population the first city of the Persian
empire, was the limit of Dr Wagner’s travels in an easterly direction.
Thence he made excursions; and finally, turning his steps
southwards, made the circuit of that extremity of Lake Urumia, and
so got back to Bayasid in Turkish Armenia; so that he visited, in fact,
but a nook of Persia—including, however, one of its most important
cities and some rarely-explored districts. His first visit at Tabriz was
to Mr Bonham, the English consul-general, with whom he found a
Maltese physician, Dr Cassolani—then the only European medical
man resident in the place—who offered him, in the kindest manner,
an apartment in his house. Here Dr Wagner interpolates a gentle
stricture on British hospitality in Asia. Mr Bonham, he says, “was
certainly also very obliging, but seemed less hospitable; and although
he had a very roomy house and a very small family, he, like his
colleague, Mr Brant at Erzroum, was not fond of putting himself out
of his way. I confess that I have not formed the most favourable
opinion of English hospitality in the East. My letters from Lord
Aberdeen and Sir Stratford Canning had not the effect which might
have been reasonably expected from the high position of those
statesmen. In Russian Asia, less exalted recommendations generally
procured me a friendly and truly hospitable reception. On better
acquaintance, and after repeated interviews, the dry, thoroughly
English reserve and formal manner gave way, in Mr Bonham, to a
certain degree of amiability. He took a particularly warm interest in
my communications from the Caucasus, and gave me in return
valuable information concerning Persian matters. Mr Bonham was
married to a niece of Sir Robert Peel’s, a beautiful, amiable, and
accomplished lady.”
In Dr Cassolani’s house Dr Wagner made the acquaintance of a
great number of Persians, who besieged the learned hekim for
advice, and he thus had excellent opportunities of noting the
peculiarities of Persian character, manners, and morals. But the most
favourable place for the pursuit of such studies, on a large scale, he
found to be the Tabriz bazaar, which is composed of a number of
bazaars, or spacious halls full of shops. Thither daily repaired Dr
Wagner, escorted by one of Dr Cassolani’s Persian servants, a fellow
of herculean proportions, whose duty it was to open a passage
through the curious crowd which at first thronged round the
European. Here were displayed prodigious masses of merchandise,
chiefly English, only the coarser kinds of goods coming from
Germany and Russia, glass from Austria, amber from
Constantinople. Here were children’s watches from Nuremberg, with
a locomotive on the dial, and the inscription, “Railway from
Nuremberg to Furth;” lithographed likenesses of the Shah of Persia,
taken and printed in Germany; snuff-boxes from Astrakan, with the
Emperor Nicholas’s portrait; and portraits of Benkendorf,
Paskewitch, Neidhard, and other Russian generals distinguished in
recent wars. There were shawls and carpets from Hindostan, and
sabre-blades, of wonderful temper and finish, from Shiraz. Of these
latter Dr Wagner saw some, adorned with beautiful arabesque
designs in gold, and inscribed with passages from the Koran, whose
price was two hundred tomauns, or Persian ducats. Made of strips of
metal, hammered together cold, these excellent blades are the result
of prodigious labour, much time, and great skill. The chief value of
such weapons is usually in the steel, for the hilt and mounting must
be unusually rich to exceed the cost of the blade itself. Hitherto the
armourers of Tabriz, Teheran, and Ispahan have vainly endeavoured
to rival those of Shiraz.
Dr Wagner soon found himself at home in the European circle at
Tabriz, which consists chiefly of the members of the Russian and
English consulates, and of the managers of four Greek commercial
houses, branches of Constantinople establishments. The English
consul-general, as already hinted, lived rather retired, gave a dinner
or two each half-year to the Europeans, and took but small share in
the pleasures and amusements after which most of them eagerly ran.
An old Greek gentleman, named Morfopulo, was the great Lucullus
and Amphitryon of the place. Introduced to him by his Maltese
friend, Dr Wagner was at once cordially invited to a dinner, which
gave him the first idea of the sumptuous manner of living of
Europeans in Tabriz. Nothing was spared; Oriental delicacies were
embalmed and ennobled by the refinements of Western art. There
were fish from the Caspian, game from the forests of Ghilan, grapes
and mulberries from Azerbijan, the most exquisite pasties, and the
cream of the vineyards of Champagne cooling in abundant ice. The
guests were as motley, the talk as various, as the viands. From East
to West, from Ispahan to Paris, the conversation rolled. The Russian
Consul-general sketched the Persian court at Teheran; Dr Cassolani
gave verbal extracts from his life and experience at Erzroum and
Tabriz; an Italian quack, who had just arrived, and who had long led
a roving existence in Asiatic Turkey—professing alternately to
discover gold mines, and to heal all maladies by an infallible elixir—
related his adventures amongst the Kourds; whilst a young Greek
diplomatist, named Mavrocordato—a relation of the statesman of
that name—just transferred, to his no small regret, from Paris to
Tabriz, was eloquent concerning the balls, beauties, and delights of
the French capital.
The domestic arrangements of the European residents in Tabriz
are peculiar, and may possibly account for the limited nature of the
intercourse maintained with them by the gentleman who filled the
post of British consul-general at the time of Dr Wagner’s visit. Some
of the managers of the Greek houses—few of whom remain more
than half-a-dozen years, which time, owing to the profitable nature
of the trade, and especially of the smuggling traffic with the trans-
Caucasian provinces of Russia, usually suffices to make their
fortunes—were married, but had left their wives in Constantinople.
Most of them, as well as the members of the Russian consulate-
general, were bachelors. All, however, whether married or single, had
conformed to the custom of the place, by contracting limited
matrimony with Nestorian women. This Christian sect, numerous in
Azerbijan, entertains a strong partiality for Europeans, and has no
scruple, either moral or religious, in marrying its daughters to them
for a fixed term of years, and in consideration of a stipulated sum.
There is great competition for a new-comer from Europe, especially
if he be rich. The queer contract is known in Tabriz as matrimonio
alla carta. Very often the whole of the lady’s family take up their
abode in the house of the temporary husband, and live at his charges;
and this is indeed often a condition of the bargain. The usage is of
such long standing amongst Europeans in Persia, and especially in
that particular province, that it there scandalises no one. Every
European has a part of his house set aside for the women, and calls it
his harem: the ladies preserve their Persian garb and manner of life,
cover their faces before strangers and in the streets, frequent the
bath, and pass their time in dressing themselves, just like the
Mahomedan Persians. Handsome, but totally uneducated and
unintellectual, they make faithful wives and tender mothers, but
poor companions. When the term stipulated in the contract expires,
and if it be not renewed, they find no difficulty in contracting
permanent marriages with their own countrymen; the less so, that, in
such cases, they take a dowry with them, whereas, in general, the
Nestorian has to purchase his wife from her parents. The children of
the European marriage almost always remain in possession of the
mother; and Dr Wagner was assured that she testifies even stronger
affection for them than for those of her second and more regular
marriage; whilst the stepfather rarely neglects his duty towards
them. “Still more remarkable is it,” continues the Doctor, “that the
European fathers, when recalled to their own country, abandon their
children, without, as it would seem, the slightest scruple of
conscience, to a most uncertain fate, and trouble themselves no
further concerning them. But a single instance is known to me, when
a wealthy European took one of his children away with him. Even in
the case of men otherwise of high character and principle, a
prolonged residence in the East seems very apt gradually to stifle the
voice of nature, of honour, and of conscience.”
Dismissing, with this reflection, the consideration of European
society and habits in Persia, Dr Wagner turns his attention to the
natives, and to an examination of the curious incidents and
vicissitudes of modern Persian history, to which he allots an
interesting chapter—based partly on his many conversations with
British and Russian diplomatic agents, with French officers who had
served in Persia, and with French and American missionaries, partly
on the works of various English travellers—and then commences his
wanderings and explorations in the mountains of Sahant, and along
the shores of Lake Urumiah. In these and other investigations,
occupying his second volume, the length to which our notice of his
first has insensibly extended forbids our accompanying him, at least
for the present. Judging from the great number of books relating to
Western Asia that have of late years been published in this country—
many of them with marked success—the number of readers who take
an interest in that region must be very considerable. By such of them
as read German, Dr Wagner’s series of six volumes will be prized as a
mine of entertainment and information.
KATIE STEWART.
A TRUE STORY.

PART II.—CHAPTER VIII.


“Leddy Kilbrachmont! Weel, John, my man, she might have done
waur—muckle waur; but I seena very weel how she could have
bettered hersel. A young, wiselike, gallant-looking lad, and a very
decent lairdship—anither thing frae a doited auld man.”
“Weel, wife,” said John Stewart, ruefully scratching his head
—“weel, I say naething against it in itsel; but will ye tell me what I’m
to say to the Beelye?”
“Ay, John, that will I,” returned the house-mother. “Tell him to
take his daughter’s bairn out of its cradle, puir wee totum, and ask
himsel what he has to do wi’ a young wife—a young wife! and a
bonnie lass like our Isabell! Man, John, to think, wi’ that muckle
body o’ yours, that you should have sae little heart! Nae wonder ye
need muckle coats and plaids about ye, you men! for ne’er a spark o’
light is in the hearts of ye, to keep ye warm within.”
“Weel, weel, Isabell; the mair cause ye should gie me a guid dram
to keep the chill out,” said the miller; “and ye’ll just mind ye were airt
and pairt, and thought mair of the Beelye’s bien dwellin’ and braw
family than ever I did; but it’s aye your way—ye put a’ the blame,
when there is blame, on me.”
“Haud your peace, guidman,” said Mrs Stewart. “Whiles I am
drawn away wi’ your reasonings against my ain judgment, as
happens to folk owre easy in their temper, whether they will or no—
I’ll no deny that; but nae man can say I ever set my face to onything
that would have broken the heart of a bairn of mine. Take your dram,
and gang away with your worldly thoughts to your worldly business,
John Stewart; if it wasna for you, I’m sure ne’er a thought of pelf
would enter my head.”
“Eh, guidwife!” It was all that the miller’s astonishment could
utter. He was put down. With humility he took the dram, and softly
setting his glass on the table, went out like a lamb, to the mill.
“Leddy Kilbrachmont! and Janet, the glaikit gilpie, taking up with
a common man!” said Mrs Stewart, unconsciously pushing aside the
pretty wheel, the offering of the “wright” in Arncreoch. “Weel, but
what maun I do? If Isabell gangs hame to her ain house, and Janet—
Janet’s a guid worker—far mair use about a house like ours than such
a genty thing as Bell—Janet married, too—what’s to come o’ me? I’ll
hae to bring hame Katie frae the Castle.”
“Muckle guid ye’ll get of Katie, mother,” said Janet, who, just then
coming in from the garden, with an armful of cold, curly, brilliant
greens, had heard her mother’s soliloquy. “If ye yokit her to the
wheel like a powny, she wadna spin the yarn for Isabell’s providing in
half-a-dozen years; and no a mortal turn besides could Katie do in a
house, if ye gied her a’ the land between this and Kellie Law.”
“And wha asked your counsel?” said the absolute sovereign of
Kellie Mill. “If I’m no sair trysted wi’ my family, there never was a
woman: first, your faither—and muckle he kens about the rule o’ a
household; and syne you, ye taupie—as if Isabell’s providing was yet
to spin! To spin, said she? and it lying safe in the oak press up the
stair, since ever Bell was a wee smout of a bairn. And yours too,
though ye dinna deserve it;—ay, and little Katie’s as weel, as the
bonnie grass on the burnside could have tellt ye twal year ago, when
it was white wi’ yarn a’ the simmer through, spun on a purpose-like
wheel—a thing fit for a woman’s wark—no a toy for a bit bairn. Gae
way wi’ you and your vanities. I would just like to see, wi’ a’ your
upsetting, ony ane o’ ye bring up a family as creditable as your
mother!”
Janet stole in to the table at the further window, and, without a
word, began to prepare her greens, which were immediately to be
added to the other contents of the great pot, which, suspended by the
crook, bubbled and boiled over the fire; for the moods of the house-
mother were pretty well known in her dominions, and no one dared
to lift up the voice of rebellion.
After an interval of silence, Mrs Stewart proceeded to her own
room, and in a short time reappeared, hooded and plaided, testifying
with those echoing steps of hers, to all concerned, that she had again
put on her high-heeled gala shoes. Isabell was now in the kitchen,
quietly going about her share of the household labour, and doing it
with a subdued graceful gladness which touched the mother’s heart.
“I’m gaun up to Kellie, Bell, my woman,” said Mrs Stewart. “I
wouldna say but we may need Katie at hame; onyway, I’ll gang up to
the Castle, and see what they say about it. It’s time she had a while at
hame to learn something purpose-like, or it’s my fear she’ll be fit for
naething but to hang on about Lady Anne; and nae bairn o’ mine
shall do that wi’ my will. Ye’ll set Merran to the muckle wheel,
Isabell, as soon as she’s in frae the field; and get that cuttie Janet to
do some creditable work. If I catch her out o’ the house when I come
hame, it’ll be the waur for hersel.”
“So ye’re aye biding on at the Castle, Bauby,” said Mrs Stewart, as,
her long walk over, she rested in the housekeeper’s room, and
greeted, with a mixture of familiarity and condescension, the
powerful Bauby, who had so long been the faithful friend and
attendant of little Katie Stewart. “Ye’re biding on? I thought you were
sure to gang with Lady Betty; and vexed I was to think of ye gaun
away, that my bairn liket sae weel.”
“I’ll never lee, Mrs Stewart,” said Bauby, confidentially. “If it hadna
just been Katie Stewart’s sel, and a thought of Lady Anne, puir thing,
left her lee lane in the house, I would as soon have gaen out to the
May to live, as bidden still in Kellie Castle. But someway they have
grippit my heart atween them—I couldna leave the bairns.”
“Aweel, Bauby, it was kind in ye,” said the miller’s wife; “but I’m in
no manner sure that I winna take Katie away.”
“Take Katie away—eh, Mrs Stewart!” And Bauby lifted up her great
hands in appeal.
“Ye see her sister Isabell is to be married soon,” said the important
mother, rising and smoothing down her skirts. “And now I’m rested,
Bauby, I’ll thank ye to take me to Lady Anne’s room.”
The fire burned brightly in the west room, glowing in the dark
polished walls, and brightening with its warm flush the clouded
daylight which shone through the high window. Again on her high
chair, with her shoulders fixed, so that she cannot stoop, Lady Anne
sits at her embroidery frame, at some distance from the window,
where the slanting light falls full upon her work, patiently and
painfully working those dim roses into the canvass which already
bears the blossoms of many a laborious hour. Poor Lady Anne!
People, all her life, have been doing their duty to her—training her
into propriety—into noiseless decorum and high-bred manners. She
has read the Spectator to improve her mind—has worked
embroidery because it was her duty; and sits resignedly in this steel
fixture now, because she feels it a duty too—a duty to the world at
large that Lady Anne Erskine should have no curve in her shoulders
—no stoop in her tall aristocratic figure. But, in spite of all this,
though they make her stiff, and pale, and silent, none of these cares
have at all tarnished the gentle lustre of Lady Anne’s good heart; for,
to tell truth, embroidery, and prejudices, and steel-collars, though
they cramp both body and mind a little, by no means have a bad
effect—or, at least, by no means so bad an effect as people ascribe to
them in these days—upon the heart; and there lived many a true lady
then—lives many a true lady now—to whom devout thoughts have
come in those dim hours, and fair fancies budded and blossomed in
the silence. It was very true that Lady Anne sat there immovable,
holding her head with conscientious firmness, as she had been
trained to hold it, and moving her long fingers noiselessly as her
needle went out and in through the canvass before her—very true
that she thought she was doing her duty, and accomplishing her
natural lot; but not any less true, notwithstanding, that the heart
which beat softly against her breast was pure and gentle as the
summer air, and, like it, touched into quiet brightness by the light
from heaven.
Near her, carelessly bending forward from a lower chair, and
leaning her whole weight on another embroidery frame, sits Katie
Stewart, labouring with a hundred wiles to draw Lady Anne’s
attention from her work. One of little Katie’s round white shoulders
is gleaming out of her dress, and she is not in the least erect, but
bends her head down between her hands, and pushes back the rich
golden hair which falls in shining, half-curled tresses over her
fingers, and laughs, and pouts, and calls to Lady Anne; but Lady
Anne only answers quietly, and goes on with her work—for it is right
and needful to work so many hours, and Lady Anne is doing her
duty.
But not so Katie Stewart: her needle lies idle on the canvass; her
silk hangs over her arm, getting soiled and dim; and Lady Anne
blushes to remember how long it is since her wayward favourite
began that group of flowers.
For Katie feels no duty—no responsibility in the matter; and
having worked a whole dreary hour, and accomplished a whole leaf,
inclines to be idle now, and would fain make her companion idle too.
But the conscientious Lady Anne shakes her head, and labours on; so
Katie, leaning still further over the frame, and still more entirely
disregarding her shoulders and deportment, tosses back the
overshadowing curls again, and with her cheeks supported in the
curved palms of her hands, and her fingers keeping back the hair
from her brow, lifts up her voice and sings—
“Corn rigs and barley rigs,
Corn rigs are bonnie.”

Sweet, clear, and full is little Katie’s voice, and she leans forward,
with her bright eyes dwelling kindly on Lady Anne’s face, while, with
affectionate pleasure, the good Lady Anne sits still, and works, and
listens—the sweet child’s voice, in which there is still scarcely a
graver modulation to tell of the coming woman, echoing into the
generous gentle heart which scarcely all its life has had a selfish
thought to interrupt the simple beautiful admiration of its unenvious
love.
“Katie, ye little cuttie!” exclaimed the horror-stricken mother,
looking in at the door.
Katie started; but it was only with privileged boldness to look up
smilingly into her mother’s face, as she finished the last verse of her
song.
“Eh, Lady Anne, what can I say to you?” said Mrs Stewart, coming
forward with indignant energetic haste; “or what will your ladyship
say to that forward monkey? Katie, have I no admonished ye to get
the manners of a serving lassie at your peril, however grand the folk
were ye saw; but, nevertheless, to gie honour where honour is due, as
it’s commanded. I think shame to look ye in the face, Lady Anne,
after hearing a bairn of mine use such a freedom.”
“But you have no need, Mrs Stewart,” said Lady Anne, “for Katie is
at home.”
There was the slightest possible tone of authority in the words,
gentle as they were; and Mrs Stewart felt herself put down.
“Weel, your ladyship kens best; but I came to speak about Katie,
Lady Anne. I’m thinking I’ll need to bring her hame.”
Mrs Stewart had her revenge. Lady Anne’s quiet face grew red and
troubled, and she struggled to loose herself from her bondage, and
turn round to face the threatening visitor.
“To take Katie home?—away from me? Oh, Mrs Stewart, dinna!”
said Lady Anne, forgetting that she was no longer a child.
“Ye see, my lady, our Isabell is to be married. The young man is
Philip Landale of Kilbrachmont. Ye may have heard tell of him even
in the Castle;—a lad with a guid house and plenty substance to take
hame a wife to; and a guid wife he’ll get to them, though maybe I
shouldna say it. And so you see, Lady Anne, I’ll be left with only
Janet at hame.”
“But, Mrs Stewart, Katie has not been accustomed to it; she could
not do you any good,” said the eager, injudicious Lady Anne.
“The very words, my lady—the very thing I said to our guidman
and the bairns at hame. ‘It’s time,’ says I, ‘that Katie was learnin’
something fit for her natural place and lot. What kind of a wife will
she ever make to a puir man, coming straight out of Kellie Castle,
and Lady Anne’s very cha’mer?’ No that I’m meaning it’s needful that
she should get a puir man, Lady Anne; but a bien man in the parish
is no like ane of your grand lords and earls; and if Katie does as weel
as her mother before her, she’ll hae a better portion than she
deserves.”
Indignantly Katie tossed her curls from her forehead, bent her
little flushed face over the frame, and began to ply her needle as if for
a wager.
“But, Mrs Stewart,” urged Lady Anne, “Katie’s birthday is not till
May, and she’s only fifteen then. Never mind the man—there’s plenty
time; but as long as we’re at Kellie, and not far away from you, Mrs
Stewart, why should not Katie live all her life with me?”
Katie glanced up archly, saucily, but said nothing.
“It wouldna be right, my lady. In the first place, you’ll no be aye at
Kellie; you’ll get folk you like better than Katie Stewart; and Katie
must depend on naebody’s will and pleasure. I’ll have it said of nae
bairn of mine that she sorned on a stranger. Na, she must come
hame.”
Lady Anne’s eyes filled with tears. The little proud belligerent
mother stood triumphant and imperious before the fire. The petulant
wilful favourite pouted over her frame; and Lady Anne looked from
one to the other with overflowing eyes.
“My sister Betty’s away, and my sister Janet’s away,” said Anne
Erskine sadly; “I’ve nobody but Katie now. If you take Katie away,
Mrs Stewart, I’ll break my heart.”
Little Katie put away her frame without saying a word, and coming
silently to the side of the high chair, knelt down, and looked
earnestly into Lady Anne’s drooping face. There was some wonder in
the look—a little awe—and then she laid down her soft cheek upon
that hand of Lady Anne’s, on which already some tears had fallen,
and taking the other hand into her own, continued to look up with a
strange, grave, sudden apprehension of the love which had been
lavished on her so long. Anne Erskine’s tears fell softly on the earnest
uplooking face, and Mrs Stewart’s heart was melted.
“Weel, Lady Anne, it’s no my nature to do a hard thing to onybody.
Keep the cuttie; I’ll no seek her as lang as I can do without her. I gie
ye my word.”
CHAPTER IX.
The west room is in no respect changed, though three years have
passed since we saw it last. In the middle of the room stands a great
open chest, already half full of carefully packed dresses. This square
flat parcel, sewed up in a linen cover, which Katie Stewart holds in
her arms as if she could with all her heart throw it out of the window,
instead of depositing it reverently in the chest, is Lady Anne’s
embroidery; and Lady Anne herself is collecting stray silks and
needle-books into a great satin bag. They are preparing for a journey.
Lady Anne Erskine is twenty—very tall, very erect, and with a most
exceptionable carriage. From her placid quiet brow the hair is
combed up, leaving not so much as one curl to shelter or shadow a
cheek which is very soft and pale indeed, but which no one could call
beautiful, or even comely. On her thin arms she wears long black
gloves which do not quite reach the elbow, but leave a part of the arm
visible under the lace ruffles which terminate her sleeves; and her
dress is of dark rustling silk, rich and heavy, though not so spotless
and youthful as it once was. Her little apron is black, and frilled with
lace; and from its pocket peeps the corner of a bright silken huswife;
for Lady Anne is no less industrious now than when she was a girl.
Ah, saucy Katie Stewart! Eighteen years old, and still no change in
you! No gloves on the round arms which clasp that covered-up
embroidery—no huswife, but a printed broadsheet ballad, the
floating light literature of the place and time, in the pocket of your
apron—no propriety in your free rebel shoulders. And people say
there is not such another pair of merry eyes in sight of Kellie Law.
The golden hair is imprisoned now, but not so closely as Lady
Anne’s, for some little curls steal lovingly down at the side, and the
fashion of combing it up clears the open white forehead, which, in
itself, is not very high, but just in proportion to the other features of
the face. Only a little taller is the round active figure—a very little. No
one is quite sensible, indeed, that Katie has made any advance in
stature at all, except herself; and even herself scarcely hopes, now in
the maturity of eighteen, to attain another half inch.
But the little girlish spirit has been growing in those quiet years. It
was Spring with her, when Katie saw the tears of Anne Erskine for
her threatened removal, and her eyes were opened then in some
degree to an appreciation of her beautiful lot. How it was that people
loved her, followed her with watchful, solicitous affection—her,
simple little Katie Stewart—the consciousness brought a strange
thrill into her heart. One may grow vain with much admiration, but
much love teaches humility. She wondered at it in her secret heart—
smiled over it with tears—and it softened and curbed her, indulged
and wilful though she was.
But all this time, in supreme contempt Katie held the rural homage
which began to be paid to her. Simple and playful as a child in Kellie,
Katie at home, when a young farmer, or sailor, or prosperous country
tradesman, or all of them together, as happened not unfrequently,
hung shyly about the fire in the Anstruther Milton, to which the
family had now removed, watching for opportunities to recommend
themselves, was as stately and dignified as any Lady Erskine of them
all. For Katie had made up her mind. Still, “a grand gentleman,”
handsome, courtly, and accomplished, with titles and honours,
wealth and birth, wandered about, a gleaming splendid shadow,
through the castles she built every day. To gain some rich and noble
wooer, of whatever kind proved attainable, was by no means Katie’s
ambition. It was a superb imagination, which walked by her side in
her dreams, naturally clothed with the grandeur which was his due;
for Katie’s mind was not very greatly developed yet—her graver
powers—and the purple of nobility and rank draped her grand figure
with natural simplicity—a guileless ideal.
“Is Lady Betty’s house a grand place, Lady Anne?” asked Katie, as
she placed the embroidery in the chest.
“It’s in the High Street,” said Lady Anne, with some pride; “not far
from the Parliament House, Katie; but it’s not like Kellie, you know;
and you that have never been in a town, may think it close, and not
like a noble house to be in a street; but the High Street and the
Canongate are grand streets; and the house is very fine too—only
Betty is alone.”
“Is Lord Colville no at home, Lady Anne?” asked Katie.
“Lord Colville’s at the sea—he’s always at the sea—and it’s dreary
for Betty to be left alone; but when she sees us, Katie, she’ll think
she’s at Kellie again.”
“And would she be glad to think that, I wonder?” said Katie, half
under her breath.
But Lady Anne did not answer, for the good Lady Anne was
making no speculations at the moment about happiness in the
abstract, and so did not properly apprehend the question of her little
friend.
The sound of a loud step hastening up stairs startled them.
Onward it came thumping through the gallery, and a breathless voice
bore it company, singing after a very strange fashion. Voice and step
were both undoubtedly Bauby Rodger’s, and the gallery creaked
under the one, and the song came forth in gasps from the other,
making itself articulate in a stormy gust as she approached the door.
“Oh handsome Charlie Stuart!
Oh charming Charlie Stuart!
There’s no a lad in a’ the land
That’s half sae sweet as thou art!”

“Bauby!” exclaimed Lady Anne with dignity, as her giant


handmaiden threw open the door—“Bauby, you have forgotten
yourself. Is that a way to enter a room where I am?”
“Your pardon, my lady—I beg your pardon—I canna help it. Eh,
Lady Anne! Eh, Miss Katie! ‘Little wat ye wha’s coming; prince and
lord and a’s coming.’ There’s ane in the court—ane frae the North, wi’
the news of a’ the victories!”
Lady Anne’s face flushed a little. “Who is it?—what is it, Bauby?”
“It’s the Prince just, blessin’s on his bonnie face!—they say he’s the
gallantest gentleman that ever was seen—making a’ the road frae the
Hielands just ae great conquish. The man says there’s thousands o’
the clans after him—a grand army, beginning wi’ the regular sodgers
in their uniform, and ending wi’ the braw tartans—or ending wi’ the
clouds mair like, for what twa e’en could see the end of them
marching, and them thousands aboon thousands; and white
cockauds on ilka bonnet of them. Eh, my leddy! I could greet—I
could dance—I could sing—
‘An somebody were come again,
Than somebody maun cross the main,
And ilka man shall hae his ain,
Carle an the King come!’”
“Hush, Bauby, hush,” said Lady Anne, drawing herself up with a
consciousness of indecorum; but her pale cheek flushed, and her face
grew animated. She could not pretend to indifference.
“Ye had best get a sword and a gun, and a white cockade yoursel.
You’re big enough, Bauby,” said the anti-Jacobite Katie; “for your
grand Chevalier will need a’ his friends yet. Maybe if you’re no
feared, but keep up with a’ thae wild Hielandmen, he’ll make you a
knight, Bauby.”
“Katie, you forget who’s beside you,” said Lady Anne.
“Oh! ne’er mind me, my lady; I’m used to argue wi’ her; but if I did
fecht for the Chevalier—ay, ye may ca’ him sae!—was it no your ain
very sel, Katie Stewart, that tellt me, nae later than yestreen, that
chivalry meant the auld grand knights that fought for the distressed
lang syne? And if I did fecht for the Prince, what should ail me? And
if it was the will of Providence to make me strong and muckle, and
you bonnie and wee, whase blame was that? The Chevalier! Ay, and
blessings on him!—for isna he just in the way of the auld chivalry—
and isna he gaun to deliver the distressed?”
“The way the King did in the persecuting times—him that shot
them down like beasts, because they liket the kirk,” said Katie.
“Eh, ye little Whig! that I should say sae! But I have nae call to
stand up for the auld kings—they’ve gaen to their place, and rendered
their account; but this bonnie lad—for a bonnie lad he is, though he’s
born a prince, and will dee a great king, as it’s my hope and desire—
has nae blame of thae ill deeds. He’s come for his ain kingdom, and
justice, and the rights of the nation, ‘and ilka man shall hae his ain.’”
“But wha’s wronged, Bauby?” asked the unbeliever.
“Wha’s wronged? Isna the nation wronged wi’ a bit German duke
pitten down in the big seat of our native king? Isna a’body wronged
that has to suffer that? And isna he coming with his white cockade to
set a’thing right again?”
“Bauby, you forget we’re to leave Kellie at twelve,” said Lady Anne,
interrupting this conclusive logic, “and the things are not all ready.
We’ll hear the true news about the Prince in Edinburgh.”
“We’ll see him, bless him! for he’s marching on Edinburgh, driving
a’ thae cowards before him like a wheen sheep,” said Bauby,
triumphantly. “I couldna keep the guid news to mysel, my lady; but
now I maun awa.”
And Bauby hastened from the room, letting her voice rise as she
went through the gallery, enough to convey to Katie’s ear her wish—
“To see guid corn upon the rigs,
And banishment to a’ the Whigs.”

After this interruption, the packing went on busily, and for a


considerable time in silence. It was the memorable year of Scottish
romance—the “forty-five;” and there were few hearts on either side
which could keep their usual pace of beating when the news of the
wild invasion was told. But like all other times of great events and
excitement, the ordinary platitudes of life ran on with wonderfully
little change—ran on, and wove themselves about those marvels; so
that this journey to Edinburgh, even in Lady Anne Erskine’s eyes, at
present bulked as largely, and looked as important, as the threatened
revolution; and to little Katie Stewart, her new gown and mantle
were greater events than the advent of the Chevalier.
“Are you no feared to go to Edinburgh, Lady Anne, and the
Chevalier and a’ his men coming?” asked Katie at length.
Katie’s own eyes sparkled at the idea, for the excitement of being
in danger was a more delightful thing than she had ever ventured to
anticipate before.
“Afraid? He is the true Prince, whether he wins or fails,” said Lady
Anne; “and no lady need fear where a Stuart reigns. It’s his right he
comes for. I pray Heaven give the Prince his right.”
Katie looked up with some astonishment. Very few things thus
moved the placid Lady Anne.
“It would only be after many a man was killed,” said Katie; “and if
the King in London comes from Germany, this Chevalier comes from
France; and his forefathers were ill men, Lady Anne.”
“Katie Stewart,” said Lady Anne, hastily, “it’s ignorance you’re
speaking. I will not hear it. I’ll hear nothing said against the right.
The Prince comes of the true royal blood. He is the son of many good
kings; and if they were not all good, that is not his fault. My fathers
served his. I will hear nothing said against the Prince’s right.”
Little Katie looked up wonderingly into her friend’s face, and then
turned away to conclude her packing. But, quite unconvinced as she
was of the claims and rights of the royal adventurer, his young
opponent said no more about Prince Charles.
CHAPTER X.
Corn-fields lie under the low green hills, here bending their golden
load under the busy reaper’s hand, there shorn and naked, with the
gathered sheaves in heaps where yesterday they grew. Pleasant
sounds are in the clear rich autumn air—harvest voices, harvest
mirth, purified by a little distance from all its coarseness; and
through the open cottage doors you see the eldest child, matronly
and important in one house, idling with a sense of guilt in the other,
who has been left at home in charge, that all elder and abler people
might get to the field. Pleasant excitement and haste touch you with
a contagious cheer and activity as you pass. Here hath our bountiful
mother been rendering riches out of her full breast once more; here,
under those broad bright, smiling heavens, the rain and the sun,
which God sends upon the just and the unjust, have day by day
cherished the seed, and brought it forth in blade and ear; and now
there is a thanksgiving in all the air, and quickened steps and
cheerful labouring proclaim the unconscious sentiment which
animates the whole. Bright, prosperous, wealthy autumn days,
wherein the reaper has no less share than his master, and the whole
world is enriched with the universal gain.
And now the Firth comes flashing into sight, making the whole
horizon a silver line, with one white sail, far off, floating on it like a
cloud. Heavily, as if it overhung the water, that dark hill prints its
bold outline on the mingled glory of sky and sea; and under its
shadow lie quiet houses, musing on the beach, so still that you could
fancy them only lingering, meditating there. But little meditation is
under those humble roofs, for the fishers of Largo are out on the
Firth, as yonder red sails tell you, straying forth at the wide mouth of
the bay; and the women at home are weaving nets, and selling fish,
and have time for anything but meditation.
But now Largo Law is left behind, and there is a grand scene
beyond. The skies are clear and distinct as skies are only in autumn;
and yonder couches the lion, who watches our fair Edinburgh night
and day; and there she stands herself, his Una, with her grey wimple
over her head, and her feet on the sands of her vassal sea. Queenlike
attendants these are: they are almost her sole glory now; for her
crown is taken from her head, and her new life of genius has scarcely
begun; but none can part the forlorn queen and her two faithful
henchmen, the Firth and the hill.
There are few other passengers to cross the ferry with our little
party; for Lady Anne has only one manservant for escort and
protection to herself, Katie Stewart, and their formidable maid. In
those days people were easily satisfied with travelling
accommodation. The ferryboat was a little dingy sloop, lifting up a
huge picturesque red sail to catch the soft wind, which carried them
along only very slowly; but Katie Stewart leaned over its grim
bulwark, watching the water—so calm, that it seemed to have
consistence and shape as the slow keel cut it asunder—softly gliding
past the little vessel’s side, and believed she had never been so
happy.
It was night when they reached Edinburgh, under the care of a
little band of Lady Colville’s servants and hangers-on—all the male
force the careful Lady Betty could muster—who had been waiting for
them at the water-side. The Chevalier’s forces were rapidly
approaching the city, and Katie Stewart’s heart thrilled with a fear
which had more delight in it than any previous joy, as slowly in their
heavy cumbrous carriage, with their little body of adherents, they
moved along through the gloom and rustling sounds of the beautiful
night. In danger! not unlike the errant ladies of the old time; and
approaching to the grand centre of romance and song—the
Edinburgh of dreams.
Lady Colville’s house was in the High Street, opposite the old Cross
of Edinburgh; and, with various very audible self-congratulations on
the part of their attendants, the visitors entered the narrow dark
gateway, and arrived in the paved court within. It was not very large
this court; and, illuminated by the fitful light of a torch, which just
showed the massy walls frowning down, with all kinds of projections
on every side, the dwelling-place of Lady Colville did not look at all
unlike one of the mysterious houses of ancient story. Here were twin
windows, set in a richly ornamented gable, sending out gleams of
fierce reflection as the light flashed into their small dark panes; and
yonder, tier above tier, the great mansion closes up darkly to the sky,
which fits the deep well of this court like a roof glowing with its “little
lot of stars.” Katie had time to observe it all while the good maternal
Lady Betty welcomed her young sister at the door. Very dark, high,
and narrow was the entrance, more like a cleft in great black rocks,
admitting to some secret cavern, than a passage between builded
walls; and the dark masses of shadow which lay in those deep
corners, and the elfin torchlight throwing wild gleams here and there
over the heavy walls, and flashing back from unseen windows,
everywhere, made a strange picturesque scene—relieved as it was by
the clear, faint stars above, and the warm light from the opened door.
But it was not at that time the most peaceful of residences, this
house of Lady Colville’s; for in a day or two Katie began to start in
her high chamber at the long boom of the Castle guns; and in these
balmy lightsome nights, excited crowds paced up and down, from the
Canongate and the Lawnmarket, and gathered in groups about the
Cross, discussing the hundred rumours to which the crisis gave birth.
At all times this Edinburgh crowd does dearly love to gather like
waves in the great street of the old city, and amuse itself with an
excitement when the times permit. As they sweep along—knots of old
men, slowly deliberating—clusters of young ones, quickening their
pace as their conversation and thoughts intensify—all in motion,
continually coming and going, the wide street never sufficiently
thronged to prevent their passage, but enough so to secure all the
animation of a crowd; and women looking on only from the “close
mouths” and outer stairs, spectators merely, not actors in the
ferment which growls too deeply for them to join—the scene is
always interesting, always exciting to a stranger; it loses somehow
the natural meanness of a vulgar mob, and you see something
historical, which quickens your pulse, and makes your blood warm,
in the angry crowd of the High Street, if it be only some frolic of
soldiers from the Castle which has roused its wrath.
Out, little Katie! out on the round balcony of that high oriel
window—something approaches which eyes of noble ladies around
you brighten to see. On the other balcony below this, Lady Anne,
with a white ribbon on her breast, leans over the carved balustrade,
eagerly looking out for its coming, with a flushed and animated face,
to which enthusiasm gives a certain charm. Even now in her
excitement she has time to look up, time to smile—though she is
almost too anxious to smile—and wave her fluttering handkerchief to
you above there, Katie Stewart, to quicken your zeal withal. But
there, little stubborn Whig, unmoved except by curiosity, and with
not a morsel of white ribbon about her whole person, and her
handkerchief thrown away into the inner room, least she should be
tempted to wave it, stands the little Hanoverian Katie, firmly
planting her feet upon the window-sill, and leaning on the great
shoulder of Bauby Rodger, who thrusts her forward from behind.
Bauby is standing on a stool within the room, her immense person
looming through the oppressed window, and one of her mighty
hands, with a handkerchief nearly as large as the main-sail of a sloop,
squeezed up within it like a ball, ready to be thrown loose to the
winds when he comes, grasping, like Lady Anne, the rail of the
balustrade.
There is a brilliant sky overhead, and all the way along, until the
street loses itself in its downward slope to the palace, those high-
crested coroneted windows are crowded with the noble ladies of
Scotland. Below, the crowd thickens every moment—a murmuring,
moving mass, with many minds within it like Katie Stewart’s, hostile
as fears for future, and remembrance of past injuries can make them,
to the hero of the day. And banners float in the air, which high above
there is misty with the palpable gold of this exceeding sunshine; and
distant music steals along the street, and far-off echoed cheers tell
that he is coming—he is coming! Pretender—Prince—Knight-errant—
the last of a doomed and hapless race.
Within the little boudoir on the lower story, which this oriel
window lights, Lady Colville sits in a great elbow chair apart, where
she can see the pageant without, and not herself be seen; for Lady
Betty wisely remembers that, though the daughter of a Jacobite earl,
she is no less the wife of a Whig lord, whose flag floats over the broad
sea far away, in the name of King George. Upon her rich stomacher
you can scarcely discern the modest white ribbon which, like an
innocent ornament, conceals itself under the folds of lace; but the
ribbon, nevertheless, is there; and ladies in no such neutral position
as hers—offshoots of the attainted house of Mar, and other gentle
cousins, crowd her other windows, though no one has seen herself on
the watch to hail the Chevalier.
And now he comes! Ah! fair, high, royal face, in whose beauty lurks
this look, like the doubtful marsh, under its mossy, brilliant verdure
—this look of wandering imbecile expression, like the passing
shadow of an idiot’s face over the face of a manful youth. Only at
times you catch it as he passes gracefully along, bowing like a prince
to those enthusiastic subjects at the windows, to those not quite so
enthusiastic in the street below. A moment, and all eyes are on him;
and now the cheer passes on—on—and the crowd follows in a stream,
and the spectators reluctantly stray in from the windows—the Prince
has past.
But Lady Anne still bends over the balustrade, her strained eyes
wandering after him, herself unconscious of the gentle call with
which Lady Betty tries to rouse her as she leaves the little room.
Quiet Anne Erskine has had no romance in her youth—shall have
none in the grave still life which, day by day, comes down to her out
of the changeful skies. Gentle affections, for sisters, brethren,
friends, are to be her portion, and her heart has never craved
another; but for this moment some strange magic has roused her.
Within her strained spirit a heroic ode is sounding; no one hears the
gradual swell of the stricken chords; no one knows how the excited
heart beats to their strange music; but give her a poet’s utterance
then, and resolve that inarticulate cadence, to which her very hand
beats time, into the words for which unconsciously she struggles, and
you should have a song to rouse a nation. Such songs there are; that
terrible Marseillaise, for instance—wrung out of a moved heart in its
highest climax and agony—the wild essence and inspiration of a
mind which was not, by natural right, a poet’s.
“Lady Anne! Lady Anne! They’re a’ past now,” said Katie Stewart.
Lady Anne’s hand fell passively from its support; her head drooped
on her breast; and over her pale cheek came a sudden burst of tears.
Quickly she stepped down from the balcony, and throwing herself
into Lady Betty’s chair, covered her face and wept.
“He’s no an ill man—I think he’s no an ill man,” said little Katie in
doubtful meditation. “I wish Prince Charlie were safe at hame; for
what will he do here?”
CHAPTER XI.
In Lady Colville’s great drawing-room a gay party had assembled.
It was very shortly after the Prestonpans victory, and the invading
party were flushed with high hopes. Something of the ancient
romance softened and refined the very manners of the time. By a
sudden revulsion those high-spirited noble people had leaped forth
from the prosaic modern life to the glowing, brilliant, eventful days
of old—as great a change almost as if the warlike barons and earls of
their family galleries had stepped out into visible life again. Here is
one young gallant, rich in lace and embroidery, describing to a knot
of earnest, eager listeners the recent battle. But for this the youth had
vegetated on his own acres, a slow, respectable squire—he is a knight
now, errant on an enterprise as daring and adventurous as ever
engaged a Sir Lancelot or Sir Tristram. The young life, indeed, hangs
in the balance—the nation’s warfare is involved; but the dangers
which surround and hem them about only brighten those youthful
eyes, and make their hearts beat the quicker. All things are possible—
the impossible they behold before them a thing accomplished; and
the magician exercises over them a power like witchcraft;—their
whole thoughts turn upon him—their speech is full of Prince Charles.
Graver are the older people—the men who risk families,
households, established rank—and whose mature minds can realise
the full risk involved. Men attainted in “the fifteen,” who remember
how it went with them then—men whom trustful retainers follow,
and on whose heads lies this vast responsibility of life and death. On
some faces among them are dark immovable clouds—on some the
desperate calmness of hearts strung to any or every loss; and few
forget, even in those brief triumphant festivities, that their lives are
in their hands.
In one of those deep window-seats, half hidden by the curtain,
Katie Stewart sits at her embroidery frame. If she never worked with
a will before, she does it now; for the little rural belle is fluttered and
excited by the presence and unusual conversation of the brilliant
company round her. The embroidery frame just suffices to mark that
Katie is Katie, and not a noble Erskine, for Lady Anne has made it
very difficult to recognise the distinction by means of the dress.
Katie’s, it is true, is plainer than her friend’s;—she has no jewels—
wears no white rose; but as much pains have been bestowed on her
toilette as on that of any lady in the room; and Lady Anne sits very
near the window, lest Katie should think herself neglected. There is
little fear—for here he stands, the grand gentleman, at Katie
Stewart’s side!
Deep in those massy walls is the recess of the window, and the
window itself is not large, and has a frame of strong broad bars, such
as might almost resist a siege. The seat is cushioned and draped with
velvet, and the heavy crimson curtain throws a flush upon Katie’s
face. Quickly move the round arms, gloved with delicate black lace,
which does not hide their whiteness; and, escaping from this cover,
the little fingers wind themselves among those bright silks, now
resting a moment on the canvass, as Katie lifts her eyes to listen to
something not quite close at hand which strikes her ear—now
impatiently beating on the frame as she droops her head, and cannot
choose but hear something very close at hand which touches her
heart.
A grand gentleman!—Manlike and gallant the young comely face
which, high up there, on the other side of those heavy crimson
draperies, bends towards her with smiles and winning looks, and
words low-spoken—brave the gay heart which beats under his rich
uniform—noble the blood that warms it. A veritable Sir Alexander,
not far from the noble house of Mar in descent, and near them in
friendship; a brave, poor baronet, young, hopeful, and enthusiastic,
already in eager joyous fancies beholding his Prince upon the British
throne, himself on the way to fortune. At first only for a hasty
moment, now and then, can he linger by Katie’s window; but the
moments grow longer and longer, and now he stands still beside her,
silently watching this bud grow upon the canvass—silently following
the motion of those hands. Little Katie dare not look up for the eyes
that rest on her—eyes which are not bold either, but have a certain
shyness in them; and as her eyelids droop over her flushed cheeks,
she thinks of the hero of her dreams, and asks herself, with innocent
wonder thrilling through her heart, if this is he?
The ladies talk beside her, as Katie cannot talk; shrewdly, simply,
within herself, she judges what they say—forms other conclusions—
pursues quite another style of reasoning—but says nothing; and Sir
Alexander leans his high brow on the crimson curtain, and
disregards them all for her.
Leaves them all to watch this bud—to establish a supervision,
under which Katie at length begins to feel uneasy, over these idling
hands of hers. Look him in the face, little Katie Stewart, and see if
those are the eyes you saw in your dreams.
But just now she cannot look him in the face. In a strange
enchanted mist she reclines in her window-seat, and dallies with her
work. Words float in upon her half-dreaming sense, fragments of
conversation which she will remember at another time; attitudes,
looks, of which she is scarcely aware now, but which will rise on her
memory hereafter, when the remembered sunshine of those days
begins to trace out the frescoes on the wall. But now the hours float
away as the pageant passed through that crowded High Street
yesterday. She is scarcely conscious of their progress as they go, but
will gaze after them when they are gone.
“And you have no white rose?” said the young cavalier.
He speaks low. Strange that he should speak low, when among so
many conversations other talkers have to raise their voices—low as
Philip Landale used to speak to Isabell.
“No,” said Katie.
He bends down further—speaks in a still more subdued tone; while
Katie’s fingers play with the silken thread, and she stoops over her
frame so closely that he cannot see her face.
“Is it possible that in Kellie one should have lived disloyal? But
that is not the greatest marvel. To be young, and fair, and generous—
is it not the same as to be a friend of the Prince? But your heart is
with the white rose, though you do not wear it on your breast?”
“No.” Look up, little Katie—up with honest eyes, that he may be
convinced. “No; his forefathers were ill men; and many a man will
die first, if Prince Charles be ever King.”
“Katie, Katie!” said the warning voice of Lady Anne, who has
caught the last words of this rebellious speech. And again the mist
steals over her in her corner; and as the light wanes and passes away
from the evening skies, she only dimly sees the bending figure beside
her, only vaguely receives into her dreaming mind the low words he
says. It is all a dream—the beautiful dim hours depart—the brilliant
groups disperse and go away; and, leaning out alone from that oriel
window, Katie Stewart looks forth upon the night.
Now and then passes some late reveller—now and then drowsily
paces past a veteran of the City Guard. The street is dark on this side,
lying in deep shadow; but the harvest moon throws its full light on
the opposite pavement, and the solitary unfrequent figures move
along, flooded in the silver radiance, which seems to take substance
and tangibility from them, and to bear them along, floating, gliding,
as the soft waters of the Firth bore the sloop across the ferry. But
here comes a quick footstep of authority, echoing through the silent
street—a rustling Highland Chief, with a dark henchman, like a
shadow at his hand; and that—what is that lingering figure looking
up to the light in Lady Anne Erskine’s window, as he slowly wends
his way downward to the Palace? Little Katie’s heart—she had
brought it out here to still it—leaps again; for this is the same form
which haunts her fancy; and again the wonder thrills through her
strangely, if thus she has come in sight of her fate.
Draw your silken mantle closer round you, Katie Stewart; put back
the golden curls which this soft breath of night stirs on your cheek,
and lean your brow upon your hand which leans upon the sculptured
stone. Slowly he passes in the moonlight, looking up at the light
which may be yours—which is not yours, little watcher, whom in the
gloom he cannot see; let your eyes wander after him, as now the full
moonbeams fill up the vacant space where a minute since his gallant
figure stood. Yes, it is true; your sunny face shines before his eyes—
your soft voice is speaking visionary words to that good simple heart
of his; and strange delight is in the thrill of wonder which moves you
to ask yourself the question—Is this the hero?
But now the sleep of youth falls on you when your head touches
the pillow. No, simple Katie, no; when the hero comes, you will not
speculate—will not ask yourself questions; but now it vexes you that
your first thoughts in the waking morrow are not of this stranger,
and neither has he been in your dreams.
For dreams are perverse—honest—and will not be persuaded into
the service of this wandering fancy. Spring up, Katie Stewart,
thankfully out of those soft, deep, dreamless slumbers, into the
glorious morning air, which fills the street between those lofty
houses like some golden fluid in an antique well;—spring up joyously
to the fresh lifetime of undiscovered hours which lie in this new day.
Grieve not that only tardily, slowly, the remembrance of the last
night’s gallant returns to your untroubled mind; soon enough will
come this fate of yours, which yet has neither darkened nor
brightened your happy skies of youth. Up with your free thoughts,
Katie, and bide your time!
A visitor of quite a different class appeared in Lady Colville’s
drawing-room that day. It was the Honourable Andrew, whose
magnificent manners had awakened Katie’s admiration at his
brother’s marriage. Not a youth, but a mature man, this Colville was
heir to the lordship; for the good Lady Betty had no children; and
while the elder brother spent his prime in the toils of his profession,
fighting and enduring upon the sea, the younger indolently dwelt at
home, acquiring, by right of a natural inclination towards the
beautiful, the character of a refined and elegant patron of the arts.
Such art as there was within his reach, he did patronise a little; but
his love of the beautiful was by no means the elevating sentiment
which we generally conclude it to be. He liked to have fine shapes
and colours ministering to his gratification—liked to appropriate and
collect around himself, his divinity, the delicate works of genius—
liked to have the world observe how fine his eye was, and how correct
his taste; and, lounging in his sister-in-law’s drawing-room, surveyed
the dark portraits on the walls, and the tall erect Lady Anne in the
corner, with the same supercilious polished smile.
Lady Betty sits in a great chair, in a rich dress of black silk, with a
lace cap over her tower of elaborate hair. She is just entering the
autumnal years; placid, gentle, full of the sunshine of kindness has
been her tranquil summer, and it has mellowed and brightened her
very face. Less harsh than in her youth are those pale lines—
softened, rounded by that kind hand of Time, which deals with her
gently, she uses him so well.
The Honourable Andrew, with his keen eyes, does not fail to notice
this, and now he begins to compliment his sister on her benign looks;
but Lady Anne is not old enough to be benign, and her movements
become constrained and awkward—her voice harsh and
unmanageable, in presence of the critic. He scans her pale face as if it
were a picture—listens when she speaks like one who endures some
uncouth sounds—is a Whig. Lady Anne could almost find it in her
heart, gentle though that heart be, to hate this supercilious Andrew
Colville.
Loop up this heavy drapery—Katie Stewart is not aware of any one
looking at her. Her fingers, threaded through these curls, support her
cheek—her shoulders are carelessly curved—her other ungloved arm
leans upon the frame of her embroidery, and her graceful little head
bends forward, looking out with absorbed unconscious eyes. Now
there comes a wakening to the dreamy face, a start to the still figure.
What is it? Only some one passing below, who lifts his bonnet from
his bright young forehead, and bows as he passes. Perhaps the bow is
for Lady Anne, faintly visible at another window. Lady Anne thinks
so, and quietly returns it as a matter of course; but not so thinks
Katie Stewart.
The Honourable Andrew Colville changes his seat: it is to bring
himself into a better light for observing that picture in the window,
which, with a critic’s delight, he notes and outlines. But Katie all the
while is quite unconscious, and now takes two or three meditative
stitches, and now leans on the frame, idly musing, without a thought
that any one sees or looks at her. By and by Mr Colville rises, to stand
by the crimson curtain where Sir Alexander stood on the previous
night, and Katie at last becomes conscious of a look of admiration
very different from the shy glances of the youthful knight. But Mr
Colville is full thirty: the little belle has a kind of compassionate
forbearance with him, and is neither angry nor fluttered. She has but
indifferent cause to be flattered, it is true, for the Honourable
Andrew admires her just as he admires the magnificent lace which
droops over his thin white hands; but still he is one of the
cognoscenti, and bestows his notice only on the beautiful.
And he talks to her, pleased with the shrewd answers which she
sometimes gives; and Katie has to rein in her wandering thoughts,
and feels guilty when she finds herself inattentive to this grandest of
grand gentlemen; while Lady Betty, looking over at them anxiously
from her great chair, thinks that little Katie’s head will be turned.
It is in a fair way; for when Mr Colville, smiling his sweetest smile
to her, has bowed himself out, and Katie goes up-stairs to change her
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like