Skip to content

Instantly share code, notes, and snippets.

@fritzvd
Last active October 14, 2015 12:14
Show Gist options
  • Save fritzvd/0b4f4f3dddcece990580 to your computer and use it in GitHub Desktop.
Save fritzvd/0b4f4f3dddcece990580 to your computer and use it in GitHub Desktop.
Mocking / Stubbing tns-core-modules for NativeScript testing on your host device
var assert = require('assert');
var proxyquire = require('proxyquire');
var fetchStub = require('node-fetch'); // the npm package not the tns-core-module (npm install --save-dev node-fetch)
var obsArray = Array;
var YourViewModel = proxyquire('../app/view-models/your-view-model',
{
fetch: fetchStub,
"data/observable-array": {
ObservableArray: Array,
'@noCallThru': true
}
});
describe('YourViewModel', function () {
describe('load', function () {
it('should load the shit', function () {
var yvm = YourViewModel();
yvm.push({title: 'this item'})
assert(yvm.length, 1);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment