ampersand-sync
Advanced tools
Comparing version 2.0.4 to 3.0.0
@@ -19,3 +19,5 @@ var _ = require('underscore'); | ||
emulateHTTP: false, | ||
emulateJSON: false | ||
emulateJSON: false, | ||
// overrideable primarily to enable testing | ||
xhrImplementation: xhr | ||
}); | ||
@@ -97,3 +99,3 @@ | ||
// With jQuery.ajax's syntax. | ||
var request = options.xhr = xhr(ajaxSettings, function (err, resp, body) { | ||
var request = options.xhr = options.xhrImplementation(ajaxSettings, function (err, resp, body) { | ||
if (err && options.error) return options.error(resp, 'error', err.message); | ||
@@ -105,3 +107,5 @@ | ||
body = JSON.parse(body); | ||
} catch (e) {} | ||
} catch (err) { | ||
if (options.error) return options.error(resp, 'error', err.message); | ||
} | ||
} | ||
@@ -108,0 +112,0 @@ if (options.success) return options.success(body, 'success', resp); |
{ | ||
"name": "ampersand-sync", | ||
"description": "Standalone, modern-browser-only version of Backbone.Sync as Common JS module.", | ||
"version": "2.0.4", | ||
"description": "Provides sync behavior for updating data from ampersand models and collections to the server.", | ||
"version": "3.0.0", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -10,3 +10,3 @@ "bugs": { | ||
"dependencies": { | ||
"qs": "^1.2.1", | ||
"qs": "^2.2.4", | ||
"underscore": "~1.6.0", | ||
@@ -13,0 +13,0 @@ "xhr": "^1.10.0" |
@@ -129,3 +129,3 @@ var test = require('tape'); | ||
test("update with just emulateJSON", function (t) { | ||
test('update with just emulateJSON', function (t) { | ||
var xhr = sync('update', getStub({ | ||
@@ -193,2 +193,19 @@ id: '2-the-tempest', | ||
test('Call provided error callback is bad JSON error.', function (t) { | ||
t.plan(3); | ||
var xhr = sync('read', getStub(), { | ||
error: function (resp, type, error) { | ||
t.deepEqual(resp, {}, 'should be passed through response'); | ||
t.equal(type, 'error', 'is string \'error\' as per jquery'); | ||
t.equal(error, 'Unable to parse JSON string', 'should be json parse message'); | ||
t.end(); | ||
}, | ||
xhrImplementation: function (ajaxSettings, callback) { | ||
callback(null, {}, '{"bad": "json'); | ||
return {}; | ||
} | ||
}); | ||
}); | ||
test('Call user provided beforeSend function.', function (t) { | ||
@@ -195,0 +212,0 @@ t.plan(1); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15993
301