can-fixture
Advanced tools
Comparing version 3.1.4 to 3.1.5
{ | ||
"name": "can-fixture", | ||
"version": "3.1.4", | ||
"version": "3.1.5", | ||
"description": "Intercept AJAX requests and simulate responses.", | ||
@@ -35,3 +35,3 @@ "main": "fixture.js", | ||
"steal": "^1.0.0", | ||
"steal-qunit": "^1.0.0", | ||
"steal-qunit": "^2.0.0", | ||
"steal-tools": "^1.0.0", | ||
@@ -38,0 +38,0 @@ "testee": "^0.9.0" |
@@ -17,4 +17,4 @@ require("./matches-test"); | ||
var errorCallback = function(xhr, status, error){ | ||
ok(false, error); | ||
start(); | ||
assert.ok(false, error); | ||
done(); | ||
}; | ||
@@ -46,4 +46,4 @@ | ||
if (__dirname !== '/') { | ||
test('static fixtures', function () { | ||
stop(); | ||
QUnit.test('static fixtures', function(assert) { | ||
var done = assert.async(); | ||
fixture('GET something', __dirname+'/fixtures/test.json'); | ||
@@ -58,3 +58,3 @@ fixture('POST something', __dirname+'/fixtures/test.json'); | ||
.then(function (data) { | ||
equal(data.sweet, 'ness', 'can.get works'); | ||
assert.equal(data.sweet, 'ness', 'can.get works'); | ||
$.ajax({ | ||
@@ -66,3 +66,3 @@ url: 'something', | ||
.then(function (data) { | ||
equal(data.sweet, 'ness', 'can.post works'); | ||
assert.equal(data.sweet, 'ness', 'can.post works'); | ||
$.ajax({ | ||
@@ -74,4 +74,4 @@ url: 'something', | ||
.then(function (data) { | ||
equal(data.sweet, 'ness', 'can.patch works'); | ||
start(); | ||
assert.equal(data.sweet, 'ness', 'can.patch works'); | ||
done(); | ||
},errorCallback); | ||
@@ -84,4 +84,4 @@ },errorCallback); | ||
if (__dirname !== '/') { | ||
test('static fixtures (using method signature)', function () { | ||
stop(); | ||
QUnit.test('static fixtures (using method signature)', function(assert) { | ||
var done = assert.async(); | ||
fixture({method: 'get', url: 'method/{id}'}, __dirname+'/fixtures/method.{id}.json'); | ||
@@ -93,4 +93,4 @@ $.ajax({ | ||
.then(function (data) { | ||
equal(data.id, 4, 'Got data with proper id using method'); | ||
start(); | ||
assert.equal(data.id, 4, 'Got data with proper id using method'); | ||
done(); | ||
}, errorCallback); | ||
@@ -101,4 +101,4 @@ }); | ||
if (__dirname !== '/') { | ||
test('static fixtures (using type signature)', function () { | ||
stop(); | ||
QUnit.test('static fixtures (using type signature)', function(assert) { | ||
var done = assert.async(); | ||
fixture({type: 'get', url: 'type/{id}'}, __dirname+'/fixtures/type.{id}.json'); | ||
@@ -110,4 +110,4 @@ $.ajax({ | ||
.then(function (data) { | ||
equal(data.id, 4, 'Got data with proper id using type'); | ||
start(); | ||
assert.equal(data.id, 4, 'Got data with proper id using type'); | ||
done(); | ||
}, errorCallback); | ||
@@ -118,4 +118,4 @@ }); | ||
if (__dirname !== '/') { | ||
test('templated static fixtures', function () { | ||
stop(); | ||
QUnit.test('templated static fixtures', function(assert) { | ||
var done = assert.async(); | ||
fixture('GET some/{id}', __dirname+'/fixtures/stuff.{id}.json'); | ||
@@ -127,4 +127,4 @@ $.ajax({ | ||
.then(function (data) { | ||
equal(data.id, 3, 'Got data with proper id'); | ||
start(); | ||
assert.equal(data.id, 3, 'Got data with proper id'); | ||
done(); | ||
}, errorCallback); | ||
@@ -134,4 +134,4 @@ }); | ||
test('dynamic fixtures', function () { | ||
stop(); | ||
QUnit.test('dynamic fixtures', function(assert) { | ||
var done = assert.async(); | ||
fixture.delay = 10; | ||
@@ -148,9 +148,9 @@ fixture('something', function () { | ||
.done(function (data) { | ||
equal(data[0].sweet, 'ness', 'can.get works'); | ||
start(); | ||
assert.equal(data[0].sweet, 'ness', 'can.get works'); | ||
done(); | ||
}); | ||
}); | ||
test('dynamic fixtures return promises', function () { | ||
stop(); | ||
QUnit.test('dynamic fixtures return promises', function(assert) { | ||
var done = assert.async(); | ||
fixture.delay = 10; | ||
@@ -167,4 +167,4 @@ fixture('something', function () { | ||
}).then(function (data) { | ||
equal(data[0].sweet, 'ness', 'can.get works'); | ||
start(); | ||
assert.equal(data[0].sweet, 'ness', 'can.get works'); | ||
done(); | ||
}); | ||
@@ -174,4 +174,5 @@ }); | ||
if (__dirname !== '/') { | ||
test('fixture function', 3, function () { | ||
stop(); | ||
QUnit.test('fixture function', function(assert) { | ||
assert.expect(3); | ||
var done = assert.async(); | ||
var url = __dirname+'/fixtures/foo.json'; | ||
@@ -184,3 +185,3 @@ fixture(url, __dirname+'/fixtures/foobar.json'); | ||
.done(function (data) { | ||
equal(data.sweet, 'ner', 'url passed works'); | ||
assert.equal(data.sweet, 'ner', 'url passed works'); | ||
fixture(url, __dirname+'/fixtures/test.json'); | ||
@@ -192,3 +193,3 @@ $.ajax({ | ||
.done(function (data) { | ||
equal(data.sweet, 'ness', 'replaced'); | ||
assert.equal(data.sweet, 'ness', 'replaced'); | ||
fixture(url, null); | ||
@@ -200,4 +201,4 @@ $.ajax({ | ||
.done(function (data) { | ||
equal(data.a, 'b', 'removed'); | ||
start(); | ||
assert.equal(data.a, 'b', 'removed'); | ||
done(); | ||
}); | ||
@@ -209,4 +210,4 @@ }); | ||
test('fixture.store fixtures', function () { | ||
stop(); | ||
QUnit.test('fixture.store fixtures', function(assert) { | ||
var done = assert.async(); | ||
@@ -247,5 +248,5 @@ var SearchText = matches.makeComparatorType(function(searchTextValue, dataSearchTextValue, data, path){ | ||
success: function (things) { | ||
equal(things.data[0].name, 'thing 29', 'first item is correct'); | ||
equal(things.data.length, 11, 'there are 11 items'); | ||
start(); | ||
assert.equal(things.data[0].name, 'thing 29', 'first item is correct'); | ||
assert.equal(things.data.length, 11, 'there are 11 items'); | ||
done(); | ||
} | ||
@@ -255,4 +256,4 @@ }); | ||
test('fixture.store fixtures should have unique IDs', function () { | ||
stop(); | ||
QUnit.test('fixture.store fixtures should have unique IDs', function(assert) { | ||
var done = assert.async(); | ||
var store = fixture.store(100, function (i) { | ||
@@ -275,6 +276,6 @@ return {name: 'Test ' + i}; | ||
var thing = things[thingKey]; | ||
ok(seenIds.indexOf(thing.id) === -1); | ||
assert.ok(seenIds.indexOf(thing.id) === -1); | ||
seenIds.push(thing.id); | ||
} | ||
start(); | ||
done(); | ||
} | ||
@@ -284,3 +285,3 @@ }); | ||
test('fixture.store should assign unique IDs when fixtures provide IDs', function () { | ||
QUnit.test('fixture.store should assign unique IDs when fixtures provide IDs', function(assert) { | ||
/* NOTE: We are testing whether the unique ID we are assigning to a new | ||
@@ -304,4 +305,4 @@ item will account for IDs which the user has provided. | ||
ajax.then(callback, function (error) { | ||
ok(false, 'ajax failure: ' + error); | ||
start(); | ||
assert.ok(false, 'ajax failure: ' + error); | ||
done(); | ||
}); | ||
@@ -319,7 +320,7 @@ } | ||
stop(); | ||
var done = assert.async(); | ||
then(request, function (response) { | ||
notEqual(response.id, 0); | ||
notEqual(response.id, 1); | ||
notEqual(response.id, 2); | ||
assert.notEqual(response.id, 0); | ||
assert.notEqual(response.id, 1); | ||
assert.notEqual(response.id, 2); | ||
@@ -332,9 +333,9 @@ /* NOTE: This check will fail if the underlying implementation changes. | ||
*/ | ||
equal(response.id, 3); | ||
assert.equal(response.id, 3); | ||
start(); | ||
done(); | ||
}); | ||
}); | ||
test('simulating an error', function () { | ||
QUnit.test('simulating an error', function(assert) { | ||
@@ -344,3 +345,3 @@ fixture('/foo', function (request, response) { | ||
}); | ||
stop(); | ||
var done = assert.async(); | ||
$.ajax({ | ||
@@ -351,16 +352,16 @@ url: '/foo', | ||
.done(function () { | ||
ok(false, 'success called'); | ||
start(); | ||
assert.ok(false, 'success called'); | ||
done(); | ||
}) | ||
.fail(function (original, type) { | ||
ok(true, 'error called'); | ||
deepEqual(JSON.parse(original.responseText), {type: "unauthorized"}, 'Original text passed'); | ||
start(); | ||
assert.ok(true, 'error called'); | ||
assert.deepEqual(JSON.parse(original.responseText), {type: "unauthorized"}, 'Original text passed'); | ||
done(); | ||
}); | ||
}); | ||
test('rand', function () { | ||
QUnit.test('rand', function(assert) { | ||
var rand = fixture.rand; | ||
var num = rand(3); | ||
equal(typeof num, 'number'); | ||
assert.equal(typeof num, 'number'); | ||
var matched = {}; | ||
@@ -373,3 +374,3 @@ // this could ocassionally fail. | ||
for(i = 0; i <= 3; i++) { | ||
ok(matched[i], "has "+i); | ||
assert.ok(matched[i], "has "+i); | ||
} | ||
@@ -390,3 +391,3 @@ | ||
for(i = 1; i <= 3; i++) { | ||
ok(matched[i], "has "+i); | ||
assert.ok(matched[i], "has "+i); | ||
delete matched[i]; | ||
@@ -396,19 +397,19 @@ } | ||
choices.forEach(function(choice){ | ||
ok(matched[choice], "has "+choice); | ||
assert.ok(matched[choice], "has "+choice); | ||
delete matched[choice]; | ||
}); | ||
ok(canReflect.size(matched) === 0, "nothing else unexpected"); | ||
assert.ok(canReflect.size(matched) === 0, "nothing else unexpected"); | ||
}); | ||
test('dataFromUrl', function () { | ||
QUnit.test('dataFromUrl', function(assert) { | ||
var data = dataFromUrl('/thingers/{id}', '/thingers/5'); | ||
equal(data.id, 5, 'gets data'); | ||
assert.equal(data.id, 5, 'gets data'); | ||
data = dataFromUrl('/thingers/5?hi.there', '/thingers/5?hi.there'); | ||
deepEqual(data, {}, 'gets data'); | ||
assert.deepEqual(data, {}, 'gets data'); | ||
}); | ||
test('core.dataFromUrl with double character value', function () { | ||
QUnit.test('core.dataFromUrl with double character value', function(assert) { | ||
var data = dataFromUrl('/days/{id}/time_slots.json', '/days/17/time_slots.json'); | ||
equal(data.id, 17, 'gets data'); | ||
assert.equal(data.id, 17, 'gets data'); | ||
}); | ||
@@ -418,3 +419,3 @@ | ||
test('fixture function gets id', function () { | ||
QUnit.test('fixture function gets id', function(assert) { | ||
fixture('/thingers/{id}', function (settings) { | ||
@@ -426,3 +427,3 @@ return { | ||
}); | ||
stop(); | ||
var done = assert.async(); | ||
$.ajax({ | ||
@@ -436,4 +437,4 @@ url: '/thingers/5', | ||
.done(function (data) { | ||
ok(data.id); | ||
start(); | ||
assert.ok(data.id); | ||
done(); | ||
}); | ||
@@ -443,3 +444,3 @@ }); | ||
if (__dirname !== '/') { | ||
test('replacing and removing a fixture', function () { | ||
QUnit.test('replacing and removing a fixture', function(assert) { | ||
var url = __dirname+'/fixtures/remove.json'; | ||
@@ -451,3 +452,3 @@ fixture('GET ' + url, function () { | ||
}); | ||
stop(); | ||
var done = assert.async(); | ||
$.ajax({ | ||
@@ -458,3 +459,3 @@ url: url, | ||
.done(function (json) { | ||
equal(json.weird, 'ness!', 'fixture set right'); | ||
assert.equal(json.weird, 'ness!', 'fixture set right'); | ||
fixture('GET ' + url, function () { | ||
@@ -470,3 +471,3 @@ return { | ||
.done(function (json) { | ||
equal(json.weird, 'ness?', 'fixture set right'); | ||
assert.equal(json.weird, 'ness?', 'fixture set right'); | ||
fixture('GET ' + url, null); | ||
@@ -478,4 +479,4 @@ $.ajax({ | ||
.done(function (json) { | ||
equal(json.weird, 'ness', 'fixture set right'); | ||
start(); | ||
assert.equal(json.weird, 'ness', 'fixture set right'); | ||
done(); | ||
}); | ||
@@ -487,3 +488,3 @@ }); | ||
test('fixture.store with can.Model', function () { | ||
QUnit.test('fixture.store with can.Model', function(assert) { | ||
var store = fixture.store(100, function (i) { | ||
@@ -509,6 +510,6 @@ return { | ||
stop(); | ||
var done = assert.async(); | ||
function errorAndStart(e){ | ||
ok(false, "borked"+e); | ||
start(); | ||
assert.ok(false, "borked"+e); | ||
done(); | ||
} | ||
@@ -522,3 +523,3 @@ | ||
}).then(function(model){ | ||
equal(model.name, 'Updated test object', 'Successfully updated object'); | ||
assert.equal(model.name, 'Updated test object', 'Successfully updated object'); | ||
}); | ||
@@ -534,4 +535,4 @@ }; | ||
equal(models.length, 100, 'Got 100 models for findAll with no parameters'); | ||
equal(models[95].name, 'Object 95', 'All models generated properly'); | ||
assert.equal(models.length, 100, 'Got 100 models for findAll with no parameters'); | ||
assert.equal(models[95].name, 'Object 95', 'All models generated properly'); | ||
return $.ajax({ | ||
@@ -542,4 +543,4 @@ url: "/models/51", | ||
.then(function (data) { | ||
equal(data.id, 51, 'Got correct object id'); | ||
equal('Object 51', data.name, 'Object name generated correctly'); | ||
assert.equal(data.id, 51, 'Got correct object id'); | ||
assert.equal('Object 51', data.name, 'Object name generated correctly'); | ||
return $.ajax({ | ||
@@ -554,3 +555,3 @@ url: "/models", | ||
.then(function (newmodel) { | ||
equal(newmodel.id, 100, 'Id got incremented'); | ||
assert.equal(newmodel.id, 100, 'Id got incremented'); | ||
// Tests creating, deleting, updating | ||
@@ -562,3 +563,3 @@ return $.ajax({ | ||
.then(function (model) { | ||
equal(model.id, 100, 'Loaded new object'); | ||
assert.equal(model.id, 100, 'Loaded new object'); | ||
return $.ajax({ | ||
@@ -582,3 +583,3 @@ url: "/models/100", | ||
.then(function (deleted) { | ||
start(); | ||
done(); | ||
},errorAndStart); | ||
@@ -595,3 +596,3 @@ | ||
test('GET fixture.store returns 404 on findOne with bad id (#803)', function () { | ||
QUnit.test('GET fixture.store returns 404 on findOne with bad id (#803)', function(assert) { | ||
var store = fixture.store(2, function (i) { | ||
@@ -605,9 +606,9 @@ return { | ||
fixture('GET /models/{id}', store.getData); | ||
stop(); | ||
var done = assert.async(); | ||
$.ajax({url: "/models/3", dataType: "json"}).then(function(){},function (data) { | ||
equal(data.status, 404, 'status'); | ||
equal(data.statusText, 'error', 'statusText'); | ||
equal(JSON.parse(data.responseText).title, 'no data', 'responseText'); | ||
start(); | ||
assert.equal(data.status, 404, 'status'); | ||
assert.equal(data.statusText, 'error', 'statusText'); | ||
assert.equal(JSON.parse(data.responseText).title, 'no data', 'responseText'); | ||
done(); | ||
}); | ||
@@ -618,3 +619,3 @@ }); | ||
// if instance isn't there. | ||
test('fixture.store returns 404 on update with a bad id (#803)', function () { | ||
QUnit.test('fixture.store returns 404 on update with a bad id (#803)', function(assert) { | ||
var store = fixture.store(5, function (i) { | ||
@@ -627,3 +628,3 @@ return { | ||
stop(); | ||
var done = assert.async(); | ||
fixture('POST /models/{id}', store.updateData); | ||
@@ -633,13 +634,13 @@ | ||
.then(function(){ | ||
QUnit.ok(false, "success"); | ||
QUnit.start(); | ||
assert.ok(false, "success"); | ||
done(); | ||
},function (data) { | ||
equal(data.status, 404, 'status'); | ||
equal(data.statusText, 'error', 'statusText'); | ||
equal(JSON.parse(data.responseText).title, 'no data', 'responseText'); | ||
start(); | ||
assert.equal(data.status, 404, 'status'); | ||
assert.equal(data.statusText, 'error', 'statusText'); | ||
assert.equal(JSON.parse(data.responseText).title, 'no data', 'responseText'); | ||
done(); | ||
}); | ||
}); | ||
test('fixture.store returns 404 on destroy with a bad id (#803)', function () { | ||
QUnit.test('fixture.store returns 404 on destroy with a bad id (#803)', function(assert) { | ||
var store = fixture.store(2, function (i) { | ||
@@ -652,3 +653,3 @@ return { | ||
stop(); | ||
var done = assert.async(); | ||
@@ -659,10 +660,10 @@ fixture('DELETE /models/{id}', store.destroyData); | ||
.then(function(){},function (data) { | ||
equal(data.status, 404, 'status'); | ||
equal(data.statusText, 'error', 'statusText'); | ||
equal(JSON.parse(data.responseText).title, 'no data', 'responseText'); | ||
start(); | ||
assert.equal(data.status, 404, 'status'); | ||
assert.equal(data.statusText, 'error', 'statusText'); | ||
assert.equal(JSON.parse(data.responseText).title, 'no data', 'responseText'); | ||
done(); | ||
}); | ||
}); | ||
test('fixture.store can use id of different type (#742)', function () { | ||
QUnit.test('fixture.store can use id of different type (#742)', function(assert) { | ||
@@ -687,12 +688,12 @@ var MustBeNumber = matches.makeComparatorType(function(queryVal, propVal){ | ||
fixture('GET /models', store.getListData); | ||
stop(); | ||
var done = assert.async(); | ||
$.ajax({url: "/models", dataType: "json", data: { filter: {parentId: '4'} } }) | ||
.then(function (models) { | ||
equal(models.data.length, 1, 'Got one model'); | ||
deepEqual(models.data[0], { id: 2, parentId: 4, name: 'Object 2' }); | ||
start(); | ||
assert.equal(models.data.length, 1, 'Got one model'); | ||
assert.deepEqual(models.data[0], { id: 2, parentId: 4, name: 'Object 2' }); | ||
done(); | ||
}); | ||
}); | ||
test('fixture("METHOD /path", store) should use the right method', function () { | ||
QUnit.test('fixture("METHOD /path", store) should use the right method', function(assert) { | ||
/* | ||
@@ -713,7 +714,7 @@ Examples: | ||
fixture('GET /models', store); // <- CHANGE | ||
stop(); | ||
var done = assert.async(); | ||
$.ajax({url: "/models", dataType: "json"}) | ||
.then(function (models) { | ||
equal(models.data.length, 100, 'Gotta catch up all!'); | ||
start(); | ||
assert.equal(models.data.length, 100, 'Gotta catch up all!'); | ||
done(); | ||
}); | ||
@@ -723,3 +724,3 @@ }); | ||
//!steal-remove-start | ||
test('fixture("METHOD /path", store) should warn when correcting to the right method', function (assert) { | ||
QUnit.test('fixture("METHOD /path", store) should warn when correcting to the right method', function (assert) { | ||
assert.expect(1); | ||
@@ -741,3 +742,4 @@ var store = fixture.store(100, function (i) { | ||
test('fixture with response callback', 4, function () { | ||
QUnit.test('fixture with response callback', function(assert) { | ||
assert.expect(4); | ||
fixture.delay = 10; | ||
@@ -752,3 +754,3 @@ fixture('responseCb', function (orig, response) { | ||
}); | ||
stop(); | ||
var done = assert.async(); | ||
$.ajax({ | ||
@@ -759,6 +761,6 @@ url: 'responseCb', | ||
.done(function (data) { | ||
equal(data.sweet, 'ness', 'can.get works'); | ||
start(); | ||
assert.equal(data.sweet, 'ness', 'can.get works'); | ||
//done(); | ||
}); | ||
stop(); | ||
//var done = assert.async(); | ||
$.ajax({ | ||
@@ -769,7 +771,7 @@ url: 'responseErrorCb', | ||
.fail(function (orig, error, text) { | ||
equal(error, 'error', 'Got error status'); | ||
equal(orig.responseText, 'This is an error from callback', 'Got error text'); | ||
start(); | ||
assert.equal(error, 'error', 'Got error status'); | ||
assert.equal(orig.responseText, 'This is an error from callback', 'Got error text'); | ||
//done(); | ||
}); | ||
stop(); | ||
//var done = assert.async(); | ||
fixture('cbWithTimeout', function (orig, response) { | ||
@@ -787,25 +789,25 @@ setTimeout(function () { | ||
.done(function (data) { | ||
equal(data[0].epic, 'ness', 'Got responsen with timeout'); | ||
start(); | ||
assert.equal(data[0].epic, 'ness', 'Got responsen with timeout'); | ||
done(); | ||
}); | ||
}); | ||
test('store create works with an empty array of items', function () { | ||
QUnit.test('store create works with an empty array of items', function(assert) { | ||
var store = fixture.store(0, function () { | ||
return {}; | ||
}); | ||
QUnit.stop(); | ||
var done = assert.async(); | ||
store.createData({ | ||
data: {} | ||
}, function (responseData, responseHeaders) { | ||
equal(responseData.id, 1, 'the first id is 1'); | ||
QUnit.start(); | ||
assert.equal(responseData.id, 1, 'the first id is 1'); | ||
done(); | ||
}); | ||
}); | ||
QUnit.test('store creates sequential ids', function () { | ||
QUnit.test('store creates sequential ids', function(assert) { | ||
var store = fixture.store(0, function () { | ||
return {}; | ||
}); | ||
QUnit.stop(); | ||
var done = assert.async(); | ||
@@ -815,3 +817,3 @@ store.createData({ | ||
}, function (responseData, responseHeaders) { | ||
equal(responseData.id, 1, 'the first id is 1'); | ||
assert.equal(responseData.id, 1, 'the first id is 1'); | ||
createSecond(); | ||
@@ -824,3 +826,3 @@ }) | ||
}, function (responseData, responseHeaders) { | ||
equal(responseData.id, 2, 'the second id is 2'); | ||
assert.equal(responseData.id, 2, 'the second id is 2'); | ||
destroyFirst(); | ||
@@ -841,4 +843,4 @@ }); | ||
}, function (responseData, responseHeaders) { | ||
equal(responseData.id, 3, 'the third id is 3'); | ||
QUnit.start(); | ||
assert.equal(responseData.id, 3, 'the third id is 3'); | ||
done(); | ||
}); | ||
@@ -853,10 +855,10 @@ } | ||
test('fixture updates request.data with id', function() { | ||
expect(1); | ||
stop(); | ||
QUnit.test('fixture updates request.data with id', function(assert) { | ||
assert.expect(1); | ||
var done = assert.async(); | ||
fixture('foo/{id}', function(request) { | ||
equal(request.data.id, 5); | ||
start(); | ||
assert.equal(request.data.id, 5); | ||
done(); | ||
}); | ||
@@ -869,3 +871,3 @@ | ||
test("create a store with array and comparison object",function(){ | ||
QUnit.test("create a store with array and comparison object",function(assert) { | ||
@@ -898,8 +900,8 @@ var SoftEq = matches.makeComparatorType(function(a, b){ | ||
fixture('GET /presetStore', store.getListData); | ||
stop(); | ||
var done = assert.async(); | ||
$.ajax({ url: "/presetStore", method: "get", data: {filter: {year: 2013, modelId:1} }, dataType: "json" }).then(function(response){ | ||
equal(response.data[0].id, 1, "got the first item"); | ||
equal(response.data.length, 1, "only got one item"); | ||
start(); | ||
assert.equal(response.data[0].id, 1, "got the first item"); | ||
assert.equal(response.data.length, 1, "only got one item"); | ||
done(); | ||
}); | ||
@@ -935,4 +937,4 @@ | ||
test("store with objects allows .create, .update and .destroy (#1471)", 4, function(){ | ||
QUnit.test("store with objects allows .create, .update and .destroy (#1471)", function(assert) { | ||
assert.expect(4); | ||
var store = fixture.store([ | ||
@@ -959,3 +961,3 @@ {id: 1, modelId: 1, year: 2013, name: "2013 Mustang", thumb: "http://mustangsdaily.com/blog/wp-content/uploads/2012/07/01-2013-ford-mustang-gt-review-585x388.jpg"}, | ||
stop(); | ||
var done = assert.async(); | ||
@@ -965,3 +967,3 @@ // $.ajax({ url: "/presetStore", method: "get", data: {year: 2013, modelId:1}, dataType: "json" }) | ||
findAll().then(function(carsData) { | ||
equal(carsData.data.length, 8, 'Got all cars'); | ||
assert.equal(carsData.data.length, 8, 'Got all cars'); | ||
return $.ajax({ url: "/cars/"+carsData.data[1].id, method: "DELETE", dataType: "json" }); | ||
@@ -971,4 +973,4 @@ }).then(function() { | ||
}).then(function(carsData) { | ||
equal(carsData.data.length, 7, 'One car less'); | ||
equal(carsData.data[1].name, '2013 Focus', 'Car actually deleted'); | ||
assert.equal(carsData.data.length, 7, 'One car less'); | ||
assert.equal(carsData.data[1].name, '2013 Focus', 'Car actually deleted'); | ||
}).then(function() { | ||
@@ -991,4 +993,4 @@ | ||
}).then(function (cars) { | ||
equal(cars.data.length, 8, 'New car created'); | ||
start(); | ||
assert.equal(cars.data.length, 8, 'New car created'); | ||
done(); | ||
}); | ||
@@ -998,3 +1000,3 @@ }); | ||
test("filtering works", function() { | ||
QUnit.test("filtering works", function(assert) { | ||
var next; | ||
@@ -1010,5 +1012,5 @@ var store = fixture.store( | ||
}); | ||
stop(); | ||
var done = assert.async(); | ||
$.getJSON('/api/cities?filter[state]=CA').then(function(data){ | ||
deepEqual(data, { | ||
assert.deepEqual(data, { | ||
data: [{ | ||
@@ -1020,11 +1022,11 @@ state : 'CA', | ||
}); | ||
QUnit.start(); | ||
done(); | ||
}, function(e){ | ||
ok(false, ""+e); | ||
start(); | ||
assert.ok(false, ""+e); | ||
done(); | ||
}); | ||
}); | ||
test("filtering works with nested props", function() { | ||
QUnit.stop(); | ||
QUnit.test("filtering works with nested props", function(assert) { | ||
var done = assert.async(); | ||
var store = fixture.store([{ | ||
@@ -1053,3 +1055,3 @@ id : 1, | ||
deepEqual(responseData, { | ||
assert.deepEqual(responseData, { | ||
count: 1, | ||
@@ -1066,12 +1068,12 @@ data: [{ | ||
}); | ||
QUnit.start(); | ||
done(); | ||
}, function(e){ | ||
ok(false); | ||
start(); | ||
assert.ok(false); | ||
done(); | ||
}); | ||
}); | ||
test("filtering works with nested.props", function() { | ||
QUnit.stop(); | ||
QUnit.test("filtering works with nested.props", function(assert) { | ||
var done = assert.async(); | ||
@@ -1097,3 +1099,3 @@ var store =fixture.store([{ | ||
.then(function(responseData){ | ||
deepEqual(responseData, { | ||
assert.deepEqual(responseData, { | ||
count: 1, | ||
@@ -1110,3 +1112,3 @@ data: [{ | ||
}); | ||
QUnit.start(); | ||
done(); | ||
}); | ||
@@ -1118,3 +1120,3 @@ | ||
QUnit.test("onreadystatechange, event is passed", function(){ | ||
QUnit.test("onreadystatechange, event is passed", function(assert) { | ||
fixture("GET something", function(){ | ||
@@ -1127,24 +1129,25 @@ return {}; | ||
xhr.onreadystatechange = function(ev){ | ||
ok(ev.target != null, "the event object passed to onreadystatechange"); | ||
start(); | ||
assert.ok(ev.target != null, "the event object passed to onreadystatechange"); | ||
done(); | ||
}; | ||
xhr.send(); | ||
stop(); | ||
var done = assert.async(); | ||
}); | ||
if (__dirname !== '/') { | ||
asyncTest("doesn't break onreadystatechange (#3)", function () { | ||
var url = __dirname + '/fixtures/test.json'; | ||
var xhr = new XMLHttpRequest(); | ||
QUnit.test("doesn't break onreadystatechange (#3)", function(assert) { | ||
var ready = assert.async(); | ||
var url = __dirname + '/fixtures/test.json'; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.onreadystatechange = function () { | ||
xhr.onreadystatechange = function () { | ||
if (xhr.readyState === 4) { | ||
ok(true, "we made a successful request"); | ||
start(); | ||
assert.ok(true, "we made a successful request"); | ||
ready(); | ||
} | ||
}; | ||
xhr.open('GET', url); | ||
xhr.send(); | ||
}); | ||
xhr.open('GET', url); | ||
xhr.send(); | ||
}); | ||
} | ||
@@ -1154,47 +1157,49 @@ | ||
test("Supports onload", function(){ | ||
QUnit.test("Supports onload", function(assert) { | ||
var xhr = new XMLHttpRequest(); | ||
QUnit.ok(("onload" in xhr), "shim passes onload detection"); | ||
assert.ok(("onload" in xhr), "shim passes onload detection"); | ||
}); | ||
if (__dirname !== '/') { | ||
asyncTest("supports addEventListener on XHR shim", function(){ | ||
var url = __dirname + '/fixtures/test.json'; | ||
var xhr = new XMLHttpRequest(); | ||
QUnit.test("supports addEventListener on XHR shim", function(assert) { | ||
var ready = assert.async(); | ||
var url = __dirname + '/fixtures/test.json'; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function(){ | ||
ok(true, "our shim supports addEventListener"); | ||
start(); | ||
xhr.addEventListener('load', function(){ | ||
assert.ok(true, "our shim supports addEventListener"); | ||
ready(); | ||
}); | ||
xhr.open('GET', url); | ||
xhr.send(); | ||
}); | ||
xhr.open('GET', url); | ||
xhr.send(); | ||
}); | ||
} | ||
if (__dirname !== '/') { | ||
asyncTest("supports removeEventListener on XHR shim", function(){ | ||
var url = __dirname + '/fixtures/test.json'; | ||
var xhr = new XMLHttpRequest(); | ||
QUnit.test("supports removeEventListener on XHR shim", function(assert) { | ||
var ready = assert.async(); | ||
var url = __dirname + '/fixtures/test.json'; | ||
var xhr = new XMLHttpRequest(); | ||
var onload = function(){ | ||
ok(false, "this should not be called"); | ||
var onload = function(){ | ||
assert.ok(false, "this should not be called"); | ||
}; | ||
xhr.addEventListener('load', onload); | ||
xhr.removeEventListener("load", onload); | ||
xhr.addEventListener('load', onload); | ||
xhr.removeEventListener("load", onload); | ||
xhr.onload = function(){ | ||
xhr.onload = function(){ | ||
setTimeout(function(){ | ||
ok(true, 'didn\'t call the event listener'); | ||
start(); | ||
assert.ok(true, 'didn\'t call the event listener'); | ||
ready(); | ||
}); | ||
}; | ||
xhr.open('GET', url); | ||
xhr.send(); | ||
}); | ||
xhr.open('GET', url); | ||
xhr.send(); | ||
}); | ||
} | ||
test("supports setDisableHeaderCheck", function(){ | ||
QUnit.test("supports setDisableHeaderCheck", function(assert) { | ||
var xhr = new XMLHttpRequest(); | ||
@@ -1204,5 +1209,5 @@ | ||
xhr.setDisableHeaderCheck(true); | ||
ok(true, "did not throw"); | ||
assert.ok(true, "did not throw"); | ||
} catch(e) { | ||
ok(false, "do not support setDisableHeaderCheck"); | ||
assert.ok(false, "do not support setDisableHeaderCheck"); | ||
} | ||
@@ -1212,40 +1217,43 @@ }); | ||
if (__dirname !== '/') { | ||
asyncTest("supports setRequestHeader", function(){ | ||
var url = __dirname + '/fixtures/test.json'; | ||
var xhr = new XMLHttpRequest(); | ||
QUnit.test("supports setRequestHeader", function(assert) { | ||
var ready = assert.async(); | ||
var url = __dirname + '/fixtures/test.json'; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.setRequestHeader("foo", "bar"); | ||
xhr.setRequestHeader("foo", "bar"); | ||
xhr.onreadystatechange = function(){ | ||
xhr.onreadystatechange = function(){ | ||
if(xhr.readyState === 4) { | ||
equal(xhr._requestHeaders.foo, "bar", "header was set"); | ||
start(); | ||
assert.equal(xhr._requestHeaders.foo, "bar", "header was set"); | ||
ready(); | ||
} | ||
}; | ||
xhr.open("GET", url); | ||
xhr.send(); | ||
}); | ||
xhr.open("GET", url); | ||
xhr.send(); | ||
}); | ||
} | ||
if (__dirname !== '/') { | ||
asyncTest("supports getResponseHeader", function(){ | ||
var url = __dirname + '/fixtures/test.json'; | ||
var xhr = new XMLHttpRequest(); | ||
QUnit.test("supports getResponseHeader", function(assert) { | ||
var ready = assert.async(); | ||
var url = __dirname + '/fixtures/test.json'; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.onreadystatechange = function(){ | ||
xhr.onreadystatechange = function(){ | ||
if(xhr.readyState === 4) { | ||
var header = xhr.getResponseHeader("Content-Type"); | ||
ok(header.indexOf("application/json") >= 0, "got correct header back"); | ||
start(); | ||
assert.ok(header.indexOf("application/json") >= 0, "got correct header back"); | ||
ready(); | ||
} | ||
}; | ||
xhr.open("GET", url); | ||
xhr.send(); | ||
}); | ||
xhr.open("GET", url); | ||
xhr.send(); | ||
}); | ||
} | ||
asyncTest("supports getAllResponseHeaders", function(){ | ||
fixture("GET something", function(req,res){ | ||
QUnit.test("supports getAllResponseHeaders", function(assert) { | ||
var ready = assert.async(); | ||
fixture("GET something", function(req,res){ | ||
res(200, { | ||
@@ -1258,20 +1266,21 @@ message: 'this is the body' | ||
var xhr = new XMLHttpRequest(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.onreadystatechange = function(){ | ||
xhr.onreadystatechange = function(){ | ||
if(xhr.readyState === 4) { | ||
var headers = xhr.getAllResponseHeaders(); | ||
var parsed = parseHeaders(headers); | ||
ok(typeof headers === "string", "got headers back"); | ||
ok(parsed.foo === "bar", "got proper values"); | ||
start(); | ||
assert.ok(typeof headers === "string", "got headers back"); | ||
assert.ok(parsed.foo === "bar", "got proper values"); | ||
ready(); | ||
} | ||
}; | ||
xhr.open("GET", "something"); | ||
xhr.send(); | ||
xhr.open("GET", "something"); | ||
xhr.send(); | ||
}); | ||
asyncTest("pass data to response handler (#13)", function(){ | ||
fixture("GET something", function(req,res){ | ||
QUnit.test("pass data to response handler (#13)", function(assert) { | ||
var ready = assert.async(); | ||
fixture("GET something", function(req,res){ | ||
res(403, { | ||
@@ -1282,53 +1291,56 @@ message: 'No bad guys' | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "something"); | ||
xhr.onreadystatechange = function(ev){ | ||
deepEqual(JSON.parse(this.responseText),{ | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "something"); | ||
xhr.onreadystatechange = function(ev){ | ||
assert.deepEqual(JSON.parse(this.responseText),{ | ||
message: 'No bad guys' | ||
}, "correct response"); | ||
equal(this.status, 403, "correct status"); | ||
start(); | ||
assert.equal(this.status, 403, "correct status"); | ||
ready(); | ||
}; | ||
xhr.send(); | ||
xhr.send(); | ||
}); | ||
asyncTest("pass return value for fixture", function(){ | ||
QUnit.test("pass return value for fixture", function(assert) { | ||
var ready = assert.async(); | ||
fixture("GET something", {foo:"bar"}); | ||
fixture("GET something", {foo:"bar"}); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "something"); | ||
xhr.onreadystatechange = function(ev){ | ||
deepEqual(JSON.parse(this.responseText),{foo:"bar"}, "correct response"); | ||
equal(this.status, 200, "correct status"); | ||
start(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "something"); | ||
xhr.onreadystatechange = function(ev){ | ||
assert.deepEqual(JSON.parse(this.responseText),{foo:"bar"}, "correct response"); | ||
assert.equal(this.status, 200, "correct status"); | ||
ready(); | ||
}; | ||
xhr.send(); | ||
xhr.send(); | ||
}); | ||
if (__dirname !== '/') { | ||
asyncTest("pass headers in fallthrough", function() { | ||
var url = __dirname+'/fixtures/foobar.json'; | ||
var xhr = new XMLHttpRequest(); | ||
expect(2); | ||
QUnit.test("pass headers in fallthrough", function(assert) { | ||
var ready = assert.async(); | ||
var url = __dirname+'/fixtures/foobar.json'; | ||
var xhr = new XMLHttpRequest(); | ||
assert.expect(2); | ||
xhr.open("GET", url); | ||
xhr.setRequestHeader("foo", "bar"); | ||
xhr.onreadystatechange = function(ev){ | ||
xhr.open("GET", url); | ||
xhr.setRequestHeader("foo", "bar"); | ||
xhr.onreadystatechange = function(ev){ | ||
var originalXhr = ev.target; | ||
if(originalXhr.readyState === 1) { | ||
originalXhr.setRequestHeader = function(key, val) { | ||
equal(key, "foo"); | ||
equal(val, "bar"); | ||
assert.equal(key, "foo"); | ||
assert.equal(val, "bar"); | ||
}; | ||
} | ||
if(originalXhr.readyState === 4) { | ||
start(); | ||
ready(); | ||
} | ||
}; | ||
xhr.send(); | ||
}); | ||
xhr.send(); | ||
}); | ||
} | ||
test("first set.Algebra CRUD works (#12)", 5, function(){ | ||
QUnit.test("first set.Algebra CRUD works (#12)", function(assert) { | ||
assert.expect(5); | ||
@@ -1365,3 +1377,3 @@ var algebra = new set.Algebra( | ||
stop(); | ||
var done = assert.async(); | ||
@@ -1371,3 +1383,3 @@ // $.ajax({ url: "/presetStore", method: "get", data: {year: 2013, modelId:1}, dataType: "json" }) | ||
findAll().then(function(carsData) { | ||
equal(carsData.data.length, 8, 'Got all cars'); | ||
assert.equal(carsData.data.length, 8, 'Got all cars'); | ||
return $.ajax({ url: "/cars/"+carsData.data[1]._id, method: "DELETE", dataType: "json" }); | ||
@@ -1377,4 +1389,4 @@ }).then(function() { | ||
}).then(function(carsData) { | ||
equal(carsData.data.length, 7, 'One car less'); | ||
equal(carsData.data[1].name, '2013 Focus', 'Car actually deleted'); | ||
assert.equal(carsData.data.length, 7, 'One car less'); | ||
assert.equal(carsData.data[1].name, '2013 Focus', 'Car actually deleted'); | ||
}).then(function() { | ||
@@ -1398,13 +1410,13 @@ | ||
}).then(function (cars) { | ||
equal(cars.data.length, 8, 'New car created'); | ||
assert.equal(cars.data.length, 8, 'New car created'); | ||
return $.ajax({ url: "/cars/5", method: "get", dataType: "json" }); | ||
}).then(function(car){ | ||
equal(car.name, "2013 Altima", "get a single car works"); | ||
start(); | ||
assert.equal(car.name, "2013 Altima", "get a single car works"); | ||
done(); | ||
}); | ||
}); | ||
test("set.Algebra CRUD works (#12)", 5, function(){ | ||
QUnit.test("set.Algebra CRUD works (#12)", function(assert) { | ||
assert.expect(5); | ||
var algebra = new set.Algebra( | ||
@@ -1440,3 +1452,3 @@ new set.Translate("where","where"), | ||
stop(); | ||
var done = assert.async(); | ||
@@ -1446,3 +1458,3 @@ // $.ajax({ url: "/presetStore", method: "get", data: {year: 2013, modelId:1}, dataType: "json" }) | ||
findAll().then(function(carsData) { | ||
equal(carsData.data.length, 8, 'Got all cars'); | ||
assert.equal(carsData.data.length, 8, 'Got all cars'); | ||
return $.ajax({ url: "/cars/"+carsData.data[1]._id, method: "DELETE", dataType: "json" }); | ||
@@ -1452,4 +1464,4 @@ }).then(function() { | ||
}).then(function(carsData) { | ||
equal(carsData.data.length, 7, 'One car less'); | ||
equal(carsData.data[1].name, '2013 Focus', 'Car actually deleted'); | ||
assert.equal(carsData.data.length, 7, 'One car less'); | ||
assert.equal(carsData.data[1].name, '2013 Focus', 'Car actually deleted'); | ||
}).then(function() { | ||
@@ -1473,14 +1485,15 @@ | ||
}).then(function (cars) { | ||
equal(cars.data.length, 8, 'New car created'); | ||
assert.equal(cars.data.length, 8, 'New car created'); | ||
return $.ajax({ url: "/cars/5", method: "get", dataType: "json" }); | ||
}).then(function(car){ | ||
equal(car.name, "2013 Altima", "get a single car works"); | ||
start(); | ||
assert.equal(car.name, "2013 Altima", "get a single car works"); | ||
done(); | ||
}); | ||
}); | ||
asyncTest("set.Algebra clauses work", function(){ | ||
QUnit.test("set.Algebra clauses work", function(assert) { | ||
var ready = assert.async(); | ||
var NumberValue = matches.makeComparatorType(function(a,b){ | ||
var NumberValue = matches.makeComparatorType(function(a,b){ | ||
if(a === b) { | ||
@@ -1495,3 +1508,3 @@ return true; | ||
var algebra = new set.Algebra( | ||
var algebra = new set.Algebra( | ||
new set.Translate("where","where"), | ||
@@ -1509,3 +1522,3 @@ set.props.id("_id"), | ||
var store = fixture.store([ | ||
var store = fixture.store([ | ||
{_id: 1, modelId: 1, year: 2013, name: "2013 Mustang", type: "used"}, | ||
@@ -1521,6 +1534,6 @@ {_id: 2, modelId: 1, year: 2014, name: "2014 Mustang", type: "new"}, | ||
fixture('GET /cars', store.getListData); | ||
fixture('GET /cars', store.getListData); | ||
$.ajax({ url: "/cars?where[year]=2013", dataType: "json" }).then(function(carsData) { | ||
equal(carsData.data.length, 4, 'Where clause works with numbers'); | ||
$.ajax({ url: "/cars?where[year]=2013", dataType: "json" }).then(function(carsData) { | ||
assert.equal(carsData.data.length, 4, 'Where clause works with numbers'); | ||
@@ -1531,3 +1544,3 @@ return $.ajax({ url: "/cars?where[year]=2013&orderBy=name", dataType: "json" }); | ||
var names = carsData.data.map(function(c){ return c.name; }); | ||
deepEqual(names, ["2013 Altima","2013 Focus","2013 Leaf","2013 Mustang"],"sort works"); | ||
assert.deepEqual(names, ["2013 Altima","2013 Focus","2013 Leaf","2013 Mustang"],"sort works"); | ||
@@ -1537,9 +1550,8 @@ return $.ajax({ url: "/cars?where[year]=2013&orderBy=name&start=1&end=2", dataType: "json" }); | ||
var names = carsData.data.map(function(c){ return c.name; }); | ||
deepEqual(names, ["2013 Focus","2013 Leaf"], "pagination works"); | ||
start(); | ||
assert.deepEqual(names, ["2013 Focus","2013 Leaf"], "pagination works"); | ||
ready(); | ||
}); | ||
}); | ||
test("storeConnection reset", function(){ | ||
QUnit.test("storeConnection reset", function(assert) { | ||
@@ -1570,7 +1582,7 @@ var algebra = new set.Algebra( | ||
}).then(function(carsData){ | ||
equal(carsData.data.length, 2, 'Got all cars'); | ||
start(); | ||
assert.equal(carsData.data.length, 2, 'Got all cars'); | ||
done(); | ||
}); | ||
stop(); | ||
var done = assert.async(); | ||
@@ -1580,4 +1592,4 @@ }); | ||
function makeAlgebraTest(fixtureUrl){ | ||
return function() { | ||
return function(assert) { | ||
assert.expect(5); | ||
var algebra = new set.Algebra( | ||
@@ -1608,6 +1620,6 @@ new set.Translate("where","where"), | ||
stop(); | ||
var done = assert.async(); | ||
findAll().then(function(carsData) { | ||
equal(carsData.data.length, 8, 'Got all cars'); | ||
assert.equal(carsData.data.length, 8, 'Got all cars'); | ||
return $.ajax({ url: "/cars/"+carsData.data[1]._id, method: "DELETE", dataType: "json" }); | ||
@@ -1617,4 +1629,4 @@ }).then(function() { | ||
}).then(function(carsData) { | ||
equal(carsData.data.length, 7, 'One car less'); | ||
equal(carsData.data[1].name, '2013 Focus', 'Car actually deleted'); | ||
assert.equal(carsData.data.length, 7, 'One car less'); | ||
assert.equal(carsData.data[1].name, '2013 Focus', 'Car actually deleted'); | ||
}).then(function() { | ||
@@ -1638,17 +1650,17 @@ | ||
}).then(function (cars) { | ||
equal(cars.data.length, 8, 'New car created'); | ||
assert.equal(cars.data.length, 8, 'New car created'); | ||
return $.ajax({ url: "/cars/5", method: "get", dataType: "json" }); | ||
}).then(function(car){ | ||
equal(car.name, "2013 Altima", "get a single car works"); | ||
start(); | ||
assert.equal(car.name, "2013 Altima", "get a single car works"); | ||
done(); | ||
}); | ||
} | ||
}; | ||
} | ||
test("set.Algebra CRUD works with easy hookup (#12)", 5, makeAlgebraTest('/cars/{_id}')); | ||
test("set.Algebra CRUD works with easy hookup and list-style url (#52)", 5, makeAlgebraTest('/cars')); | ||
QUnit.test("set.Algebra CRUD works with easy hookup (#12)", makeAlgebraTest('/cars/{_id}')); | ||
QUnit.test("set.Algebra CRUD works with easy hookup and list-style url (#52)", makeAlgebraTest('/cars')); | ||
test("store.getList and store.get", function(){ | ||
QUnit.test("store.getList and store.get", function(assert) { | ||
@@ -1670,25 +1682,26 @@ var algebra = new set.Algebra( | ||
equal( store.getList({year: 2013}).data.length, 4, "filtered"); | ||
assert.equal( store.getList({year: 2013}).data.length, 4, "filtered"); | ||
deepEqual(store.get({_id: 5}).name, "2013 Altima", "get"); | ||
assert.deepEqual(store.get({_id: 5}).name, "2013 Altima", "get"); | ||
}); | ||
asyncTest("supports addEventListener on shim using fixture", function(){ | ||
fixture("/addEventListener", function(){ | ||
QUnit.test("supports addEventListener on shim using fixture", function(assert) { | ||
var ready = assert.async(); | ||
fixture("/addEventListener", function(){ | ||
return {}; | ||
}); | ||
var xhr = new XMLHttpRequest(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function(){ | ||
ok(true, "our shim supports addEventListener"); | ||
start(); | ||
xhr.addEventListener('load', function(){ | ||
assert.ok(true, "our shim supports addEventListener"); | ||
ready(); | ||
}); | ||
xhr.open('GET', "/addEventListener"); | ||
xhr.send(); | ||
xhr.open('GET', "/addEventListener"); | ||
xhr.send(); | ||
}); | ||
if (__dirname !== '/') { | ||
test("supports sync on XHR shim (#23)", function(){ | ||
QUnit.test("supports sync on XHR shim (#23)", function(assert) { | ||
var url = __dirname + '/fixtures/test.json'; | ||
@@ -1698,3 +1711,3 @@ var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function(){ | ||
ok(true, "our shim supports addEventListener"); | ||
assert.ok(true, "our shim supports addEventListener"); | ||
}); | ||
@@ -1707,3 +1720,3 @@ | ||
test("supports sync fixtures (#23)", function(){ | ||
QUnit.test("supports sync fixtures (#23)", function(assert) { | ||
fixture("/sync", function(){ | ||
@@ -1715,3 +1728,3 @@ return {}; | ||
xhr.addEventListener('load', function(){ | ||
ok(true, "our shim supports sync"); | ||
assert.ok(true, "our shim supports sync"); | ||
}); | ||
@@ -1724,3 +1737,3 @@ | ||
if (__dirname !== '/') { | ||
test("supports sync redirect fixtures (#23)", function(){ | ||
QUnit.test("supports sync redirect fixtures (#23)", function(assert) { | ||
fixture("/sync_redirect", __dirname+'/fixtures/test.json'); | ||
@@ -1731,3 +1744,3 @@ | ||
xhr.addEventListener('load', function(){ | ||
ok(true, "our shim supports sync redirect"); | ||
assert.ok(true, "our shim supports sync redirect"); | ||
}); | ||
@@ -1741,80 +1754,84 @@ | ||
if (__dirname !== '/') { | ||
asyncTest("slow mode works (#26)", function(){ | ||
var url = __dirname + '/fixtures/test.json'; | ||
fixture({url: url}, 1000); | ||
QUnit.test("slow mode works (#26)", function(assert) { | ||
var ready = assert.async(); | ||
var url = __dirname + '/fixtures/test.json'; | ||
fixture({url: url}, 1000); | ||
var xhr = new XMLHttpRequest(); | ||
var xhr = new XMLHttpRequest(); | ||
var startTime = new Date(); | ||
var startTime = new Date(); | ||
xhr.addEventListener('load', function(){ | ||
xhr.addEventListener('load', function(){ | ||
var delay = new Date() - startTime; | ||
ok(delay >= 900, delay + "ms >= 900ms"); | ||
assert.ok(delay >= 900, delay + "ms >= 900ms"); | ||
fixture({url: url}, null); | ||
start(); | ||
ready(); | ||
}); | ||
xhr.open('GET', url); | ||
xhr.send(); | ||
}); | ||
xhr.open('GET', url); | ||
xhr.send(); | ||
}); | ||
} | ||
asyncTest('onload should be triggered for HTTP error responses (#36)', function() { | ||
fixture('/onload', function(req, res) { | ||
QUnit.test('onload should be triggered for HTTP error responses (#36)', function(assert) { | ||
var done = assert.async(); | ||
fixture('/onload', function(req, res) { | ||
res(400); | ||
}); | ||
var xhr = new XMLHttpRequest(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function() { | ||
ok(true, 'onload should be invoked'); | ||
xhr.addEventListener('load', function() { | ||
assert.ok(true, 'onload should be invoked'); | ||
fixture('/onload', null); | ||
start(); | ||
done(); | ||
}); | ||
xhr.addEventListener('error', function() { | ||
ok(false, 'onerror should not be invoked'); | ||
xhr.addEventListener('error', function() { | ||
assert.ok(false, 'onerror should not be invoked'); | ||
fixture('/onload', null); | ||
start(); | ||
done(); | ||
}); | ||
xhr.open('GET', '/onload'); | ||
xhr.send(); | ||
xhr.open('GET', '/onload'); | ||
xhr.send(); | ||
}); | ||
asyncTest('responseText & responseXML should not be set for arraybuffer types (#38)', function() { | ||
QUnit.test('responseText & responseXML should not be set for arraybuffer types (#38)', function(assert) { | ||
var done = assert.async(); | ||
fixture('/onload', '/test/fixtures/foo.json'); | ||
fixture('/onload', '/test/fixtures/foo.json'); | ||
var oldError = window.onerror; | ||
var oldError = window.onerror; | ||
window.onerror = function (msg, url, line) { | ||
ok(false, 'There should not be an error'); | ||
start(); | ||
window.onerror = function (msg, url, line) { | ||
assert.ok(false, 'There should not be an error'); | ||
done(); | ||
}; | ||
var xhr = new XMLHttpRequest(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function() { | ||
xhr.addEventListener('load', function() { | ||
fixture('/onload', null); | ||
window.onerror = oldError; | ||
ok(true, 'Got here without an error'); | ||
start(); | ||
assert.ok(true, 'Got here without an error'); | ||
done(); | ||
}); | ||
xhr.responseType = 'arraybuffer'; | ||
xhr.open('GET', '/onload'); | ||
xhr.send(); | ||
xhr.responseType = 'arraybuffer'; | ||
xhr.open('GET', '/onload'); | ||
xhr.send(); | ||
}); | ||
asyncTest('fixture with timeout does not run if $.ajax timeout less than delay', function() { | ||
var delay = fixture.delay; | ||
fixture.delay = 1000; | ||
fixture('/onload', function() { | ||
QUnit.test('fixture with timeout does not run if $.ajax timeout less than delay', function(assert) { | ||
var done = assert.async(); | ||
var delay = fixture.delay; | ||
fixture.delay = 1000; | ||
fixture('/onload', function() { | ||
fixture('/onload', null); | ||
ok(false, 'timed out xhr did not abort'); | ||
start(); | ||
assert.ok(false, 'timed out xhr did not abort'); | ||
done(); | ||
}); | ||
$.ajax({ | ||
$.ajax({ | ||
url: '/onload', | ||
@@ -1824,32 +1841,34 @@ timeout: 50, | ||
fixture('/onload', null); | ||
ok(true, 'Got to the error handler'); | ||
equal(xhr.statusText, "timeout"); | ||
equal(xhr.status, "0"); | ||
start(); | ||
assert.ok(true, 'Got to the error handler'); | ||
assert.equal(xhr.statusText, "timeout"); | ||
assert.equal(xhr.status, "0"); | ||
done(); | ||
} | ||
}); | ||
fixture.delay = delay; | ||
fixture.delay = delay; | ||
}); | ||
asyncTest("response headers are set", function(){ | ||
fixture("GET /todos", function(request, response){ | ||
QUnit.test("response headers are set", function(assert) { | ||
var ready = assert.async(); | ||
fixture("GET /todos", function(request, response){ | ||
response(200, "{}", { foo: "bar"}); | ||
}); | ||
var xhr = new XMLHttpRequest(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function(){ | ||
xhr.addEventListener('load', function(){ | ||
var headers = parseHeaders(xhr.getAllResponseHeaders()); | ||
ok(headers.foo === "bar", "header was set"); | ||
start(); | ||
assert.ok(headers.foo === "bar", "header was set"); | ||
ready(); | ||
}); | ||
xhr.open('GET', "/todos"); | ||
xhr.send(); | ||
xhr.open('GET', "/todos"); | ||
xhr.send(); | ||
}); | ||
asyncTest("match values in get data", function(){ | ||
fixture({ | ||
QUnit.test("match values in get data", function(assert) { | ||
var ready = assert.async(); | ||
fixture({ | ||
method: "GET", | ||
@@ -1859,34 +1878,35 @@ url: "/data-value", | ||
}, function(request, response){ | ||
QUnit.ok(true, "got it"); | ||
assert.ok(true, "got it"); | ||
return {}; | ||
}); | ||
var xhr = new XMLHttpRequest(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function(){ | ||
QUnit.start(); | ||
xhr.addEventListener('load', function(){ | ||
ready(); | ||
}); | ||
xhr.open('GET', "/data-value?name=justin&age=22"); | ||
xhr.send(); | ||
xhr.open('GET', "/data-value?name=justin&age=22"); | ||
xhr.send(); | ||
}); | ||
asyncTest("universal match (#2000)", function(){ | ||
fixture({},function(){ | ||
ok(true, "got hit"); | ||
QUnit.test("universal match (#2000)", function(assert) { | ||
var ready = assert.async(); | ||
fixture({},function(){ | ||
assert.ok(true, "got hit"); | ||
return {}; | ||
}); | ||
var xhr = new XMLHttpRequest(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function(){ | ||
QUnit.start(); | ||
xhr.addEventListener('load', function(){ | ||
ready(); | ||
fixture.fixtures.splice(0, fixture.fixtures.length); | ||
}); | ||
xhr.open('GET', "/something-totally-unexpected-62"); | ||
xhr.send(); | ||
xhr.open('GET', "/something-totally-unexpected-62"); | ||
xhr.send(); | ||
}); | ||
test("set.Algebra stores provide a count (#58)", function(){ | ||
QUnit.test("set.Algebra stores provide a count (#58)", function(assert) { | ||
@@ -1914,49 +1934,51 @@ var algebra = new set.Algebra( | ||
stop(); | ||
var done = assert.async(); | ||
$.ajax({ url: "/cars", dataType: "json", data: {start: 2, end: 3} }).then(function(carsData) { | ||
equal(carsData.data.length, 2, 'Got 2 cars'); | ||
equal(carsData.count, 8, "got the count"); | ||
QUnit.start(); | ||
assert.equal(carsData.data.length, 2, 'Got 2 cars'); | ||
assert.equal(carsData.count, 8, "got the count"); | ||
done(); | ||
}, function(){ | ||
QUnit.ok(false, "borked"); | ||
QUnit.start(); | ||
assert.ok(false, "borked"); | ||
done(); | ||
}); | ||
}); | ||
asyncTest('should allow Arrays as data type (#133)', function() { | ||
fixture('/array-data', function(req, res) { | ||
ok(req.data instanceof Array, 'data returned should be instance of Array'); | ||
QUnit.test('should allow Arrays as data type (#133)', function(assert) { | ||
var ready = assert.async(); | ||
fixture('/array-data', function(req, res) { | ||
assert.ok(req.data instanceof Array, 'data returned should be instance of Array'); | ||
return {}; | ||
}); | ||
var data = []; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function() { | ||
var data = []; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function() { | ||
fixture('/array-data', null); | ||
ok(true, 'should not throw when sending Array'); | ||
start(); | ||
assert.ok(true, 'should not throw when sending Array'); | ||
ready(); | ||
}); | ||
xhr.open('GET', '/array-data'); | ||
xhr.send(data); | ||
xhr.open('GET', '/array-data'); | ||
xhr.send(data); | ||
}); | ||
asyncTest('should allow FormData as data type (#133)', function() { | ||
fixture('/upload', function(req, res) { | ||
ok(req.data instanceof FormData, 'data returned should be instance of formdata'); | ||
QUnit.test('should allow FormData as data type (#133)', function(assert) { | ||
var ready = assert.async(); | ||
fixture('/upload', function(req, res) { | ||
assert.ok(req.data instanceof FormData, 'data returned should be instance of formdata'); | ||
res(400); | ||
}); | ||
var data = new FormData(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function() { | ||
var data = new FormData(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function() { | ||
fixture('/upload', null); | ||
ok(true, 'should not throw when sending FormData'); | ||
start(); | ||
assert.ok(true, 'should not throw when sending FormData'); | ||
ready(); | ||
}); | ||
xhr.open('POST', '/upload', true); | ||
xhr.send(data); | ||
xhr.open('POST', '/upload', true); | ||
xhr.send(data); | ||
}); | ||
test('fixture returns the old fixture callback when fixtures are removed (#34)', function() { | ||
QUnit.test('fixture returns the old fixture callback when fixtures are removed (#34)', function(assert) { | ||
var funcA = function(){ | ||
@@ -1969,14 +1991,15 @@ return "foo"; | ||
var oldFixtures = fixture("/services/thing", null); | ||
QUnit.deepEqual(oldFixtures, [{fixture: funcA, url: '/services/thing'}]); | ||
assert.deepEqual(oldFixtures, [{fixture: funcA, url: '/services/thing'}]); | ||
}); | ||
if ("onabort" in XMLHttpRequest._XHR.prototype) { | ||
asyncTest('fixture with timeout aborts if xhr timeout less than delay', function() { | ||
fixture('/onload', 1000); | ||
QUnit.test('fixture with timeout aborts if xhr timeout less than delay', function(assert) { | ||
var done = assert.async(); | ||
fixture('/onload', 1000); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', '/onload'); | ||
xhr.send(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', '/onload'); | ||
xhr.send(); | ||
setTimeout(function() { | ||
setTimeout(function() { | ||
xhr.abort(); | ||
@@ -1986,47 +2009,47 @@ }, 50); | ||
xhr.addEventListener('abort', function() { | ||
xhr.addEventListener('abort', function() { | ||
fixture('/onload', null); | ||
ok(true, 'Got to the error handler'); | ||
equal(xhr.statusText, ''); | ||
equal(xhr.status, 0); | ||
start(); | ||
assert.ok(true, 'Got to the error handler'); | ||
assert.equal(xhr.statusText, ''); | ||
assert.equal(xhr.status, 0); | ||
done(); | ||
}); | ||
xhr.addEventListener('load', function() { | ||
xhr.addEventListener('load', function() { | ||
fixture('/onload', null); | ||
ok(false, 'timed out xhr did not abort'); | ||
start(); | ||
assert.ok(false, 'timed out xhr did not abort'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
asyncTest('dynamic fixture with timeout does not run if xhr timeout less than delay', function() { | ||
var delay = fixture.delay; | ||
fixture.delay = 1000; | ||
fixture('/onload', function() { | ||
QUnit.test('dynamic fixture with timeout does not run if xhr timeout less than delay', function(assert) { | ||
var done = assert.async(); | ||
var delay = fixture.delay; | ||
fixture.delay = 1000; | ||
fixture('/onload', function() { | ||
fixture('/onload', null); | ||
ok(false, 'timed out xhr did not abort'); | ||
start(); | ||
assert.ok(false, 'timed out xhr did not abort'); | ||
done(); | ||
}); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', '/onload'); | ||
setTimeout(function() { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', '/onload'); | ||
setTimeout(function() { | ||
xhr.abort(); | ||
}, 50); | ||
xhr.send(); | ||
xhr.send(); | ||
xhr.addEventListener('abort', function() { | ||
xhr.addEventListener('abort', function() { | ||
fixture('/onload', null); | ||
ok(true, 'Got to the error handler'); | ||
equal(xhr.statusText, ''); | ||
equal(xhr.status, 0); | ||
start(); | ||
assert.ok(true, 'Got to the error handler'); | ||
assert.equal(xhr.statusText, ''); | ||
assert.equal(xhr.status, 0); | ||
done(); | ||
}); | ||
fixture.delay = delay; | ||
}); | ||
fixture.delay = delay; | ||
}); | ||
test("abort() sets readyState correctly", function(){ | ||
stop(); | ||
QUnit.test("abort() sets readyState correctly", function(assert) { | ||
var done = assert.async(); | ||
@@ -2042,9 +2065,9 @@ fixture('/foo', function() { | ||
fixture('/foo', null); | ||
ok(true, 'Got to the error handler'); | ||
equal(xhr.status, 0); | ||
equal(xhr.statusText, ''); | ||
assert.ok(true, 'Got to the error handler'); | ||
assert.equal(xhr.status, 0); | ||
assert.equal(xhr.statusText, ''); | ||
setTimeout(function(){ | ||
equal(xhr.readyState, 0); | ||
start(); | ||
assert.equal(xhr.readyState, 0); | ||
done(); | ||
}, 50); | ||
@@ -2057,4 +2080,4 @@ }); | ||
test("abort() of already completed fixture", function(){ | ||
stop(); | ||
QUnit.test("abort() of already completed fixture", function(assert) { | ||
var done = assert.async(); | ||
@@ -2070,5 +2093,5 @@ fixture('/foo', function() { | ||
fixture('/foo', null); | ||
equal(xhr.readyState, 4); | ||
assert.equal(xhr.readyState, 4); | ||
xhr.abort(); | ||
start(); | ||
done(); | ||
}); | ||
@@ -2079,24 +2102,25 @@ | ||
asyncTest('should be able to call getResponseHeader onload', function() { | ||
fixture('/onload', function(req, res) { | ||
QUnit.test('should be able to call getResponseHeader onload', function(assert) { | ||
var ready = assert.async(); | ||
fixture('/onload', function(req, res) { | ||
res(400); | ||
}); | ||
var xhr = new XMLHttpRequest(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function() { | ||
xhr.addEventListener('load', function() { | ||
fixture('/onload', null); | ||
xhr.getResponseHeader('Set-Cookie'); | ||
ok(true, 'should not throw when calling getResponseHeader'); | ||
start(); | ||
assert.ok(true, 'should not throw when calling getResponseHeader'); | ||
ready(); | ||
}); | ||
xhr.open('GET', '/onload'); | ||
xhr.send(); | ||
}); | ||
xhr.open('GET', '/onload'); | ||
xhr.send(); | ||
}); | ||
testHelpers.dev.devOnlyTest("window.fixture warns when called", function() { | ||
testHelpers.dev.devOnlyTest("window.fixture warns when called", function (assert) { | ||
var teardown = testHelpers.dev.willWarn(/You are using the global fixture\. Make sure you import can-fixture\./, function(message, matched) { | ||
if(matched) { | ||
ok(true, "received warning"); | ||
assert.ok(true, "received warning"); | ||
} | ||
@@ -2112,3 +2136,3 @@ }); | ||
testHelpers.dev.devOnlyTest("Works with steal-clone", function() { | ||
testHelpers.dev.devOnlyTest("Works with steal-clone", function (assert) { | ||
steal.loader.import("steal-clone", { name: "can-fixture" }) | ||
@@ -2124,4 +2148,4 @@ .then(function(clone) { | ||
fixture('/onload', null); | ||
QUnit.ok(true, "Got to the load event without throwing"); | ||
start(); | ||
assert.ok(true, "Got to the load event without throwing"); | ||
done(); | ||
}); | ||
@@ -2133,3 +2157,3 @@ xhr.open('GET', '/onload'); | ||
stop(); | ||
var done = assert.async(); | ||
}); | ||
@@ -2136,0 +2160,0 @@ } // END onabort check |
@@ -5,3 +5,3 @@ var QUnit = require('steal-qunit'); | ||
QUnit.test('core.defaultCompare', function () { | ||
QUnit.test('core.defaultCompare', function(assert) { | ||
@@ -13,3 +13,3 @@ var same = matches.request({ | ||
}); | ||
ok(same, 'they are similar'); | ||
assert.ok(same, 'they are similar'); | ||
@@ -21,6 +21,6 @@ same = matches.request({ | ||
}); | ||
ok(!same, 'they are not the same'); | ||
assert.ok(!same, 'they are not the same'); | ||
}); | ||
QUnit.test('core.matches', function () { | ||
QUnit.test('core.matches', function(assert) { | ||
var same = matches.matches({ | ||
@@ -32,3 +32,3 @@ url: '/thingers/5' | ||
ok(same, 'similar'); | ||
assert.ok(same, 'similar'); | ||
same = matches.matches({ | ||
@@ -40,3 +40,3 @@ url: '/thingers/5', | ||
}); | ||
ok(same, 'similar with extra pops on settings'); | ||
assert.ok(same, 'similar with extra pops on settings'); | ||
var exact = matches.matches({ | ||
@@ -48,3 +48,3 @@ url: '/thingers/5', | ||
}, true); | ||
ok(!exact, 'not exact'); | ||
assert.ok(!exact, 'not exact'); | ||
exact = matches.matches({ | ||
@@ -55,3 +55,3 @@ url: '/thingers/5' | ||
}, true); | ||
ok(exact, 'exact'); | ||
assert.ok(exact, 'exact'); | ||
}); |
@@ -15,3 +15,3 @@ var QUnit = require('steal-qunit'); | ||
QUnit.stop(); | ||
var done = assert.async(); | ||
store.createInstance({name: "bar"}).then(function(instance){ | ||
@@ -48,7 +48,7 @@ var data = store.getList({}); | ||
}); | ||
QUnit.start(); | ||
done(); | ||
}); | ||
}); | ||
QUnit.test("anything with a schema will be converted to a queryLogic automatically", function(){ | ||
QUnit.test("anything with a schema will be converted to a queryLogic automatically", function(assert) { | ||
var store = fixture.store( | ||
@@ -60,3 +60,3 @@ [ {_id: 0, name: "foo"} ], | ||
var res = store.get({_id: 0}); | ||
QUnit.ok(res, "an object works"); | ||
assert.ok(res, "an object works"); | ||
@@ -75,4 +75,4 @@ var type = canReflect.assignSymbols({},{ | ||
res = store.get({_id: 0}); | ||
QUnit.ok(res, "an object works"); | ||
//.then(function(){ QUnit.ok(true, "got data"); }); | ||
assert.ok(res, "an object works"); | ||
//.then(function(){ assert.ok(true, "got data"); }); | ||
@@ -88,8 +88,8 @@ | ||
QUnit.stop(); | ||
var done = assert.async(); | ||
store.createData({ | ||
data: {name: "bar"} | ||
}, function(instance){ | ||
QUnit.deepEqual(instance, {id: 1, name: "bar"} ); | ||
QUnit.start(); | ||
assert.deepEqual(instance, {id: 1, name: "bar"} ); | ||
done(); | ||
}); | ||
@@ -116,4 +116,4 @@ /* | ||
}); | ||
QUnit.start(); | ||
done(); | ||
});*/ | ||
}); |
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
145511
3244