Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Backbone.js Testing
  • Table Of Contents Toc
Backbone.js Testing

Backbone.js Testing

By : Ryan Glenn Roemer
4.9 (14)
close
close
Backbone.js Testing

Backbone.js Testing

4.9 (14)
By: Ryan Glenn Roemer

Overview of this book

Table of Contents (13 chapters)
close
close
Backbone.js Testing
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1
Index

Writing Mocha test specifications


With practically everything else in place, we finally turn to writing test specifications. Mocha BDD specifications are declared using the it() function with the following function signature:

it(description, callback);

The description string, by convention, is a statement of the expected behavior under test, and the callback function executes the tests. For example, assuming we have an empty this.notes collection variable, a test of the default values in App.Collections.Notes can be as simple as the following:

it("has default values", function () {
  expect(this.notes).to.be.ok;
  expect(this.notes).to.have.length(0);
});

Asynchronous behavior in tests

Although basic test specifications are quite simple, flow control complications arise when testing asynchronous application code. Given that the Backbone.js application's behavior is quite often asynchronous/event-driven, we need to have a solid and straightforward test approach.

Fortunately, Mocha provides an...

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Backbone.js Testing
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon