Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with NativeScript

You're reading from   Getting Started with NativeScript Explore the possibility of building truly native, cross-platform mobile applications using your JavaScript skill—NativeScript!

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher
ISBN-13 9781785888656
Length 168 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Nathanael J. Anderson Nathanael J. Anderson
Author Profile Icon Nathanael J. Anderson
Nathanael J. Anderson
Arrow right icon
View More author details
Toc

Local testing of your code


Let's look at testing the WebSocketWrapper.js file. At the top of it, it requires nativescript-websockets code. Well, the nativescript-websockets code only runs on Android or iOS. It doesn't run on your development machine. So, how are you going to test it?

You will use Proxyquire. Proxyquire is a Nifty library that allows you to replace any require statements during tests without modifying the code that you are testing. Using it allows you to dynamically replace the functions and classes exported from a module with mock or dummy replacements. A require statement would load the exported functions and classes into your code. So, let's look at the top part of the testWebSockets.js file:

var proxyquire = require('proxyquire');
var assert = require('assert');

var DummyWS = function() {
  this._isOpen = false;
  this._events = {};
};
DummyWS.prototype.on = function(event, callback) {
  if (!this._events[event]) { this._events[event] = [];}
  this._events[event].push...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime