Skip to content

Commit

Permalink
Merge pull request #172 from canjs/typed-upd
Browse files Browse the repository at this point in the history
Serialize typed properties
  • Loading branch information
matthewp committed Jun 24, 2019
2 parents e5b53ae + 2604c96 commit fa001c5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"can-reflect": "^1.15.1"
},
"devDependencies": {
"can-define": "^2.7.18",
"can-set-legacy": "<2.0.0",
"can-test-helpers": "^1.1.2",
"detect-cyclic-packages": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion store.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function typeConvert(data){
var copy = {};
canReflect.eachKey(data, function(value, key){
if(keys[key]) {
copy[key] = canReflect.convert(value, keys[key]);
copy[key] = canReflect.serialize(canReflect.convert(value, keys[key]));
} else {
copy[key] = value;
}
Expand Down
46 changes: 42 additions & 4 deletions test/fixture_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var canReflect = require("can-reflect");
var matches = require("../matches");
var QueryLogic = require("can-query-logic");
var testHelpers = require("can-test-helpers");
var DefineMap = require("can-define/map/map");


var errorCallback = function(xhr, status, error){
Expand Down Expand Up @@ -1876,6 +1877,46 @@ QUnit.test('fixture returns the old fixture callback when fixtures are removed (
assert.deepEqual(oldFixtures, [{fixture: funcA, url: '/services/thing'}]);
});

QUnit.test("Using with nested types", function(assert){
var done = assert.async();

var Pet = DefineMap.extend("Pet", {
name: "string"
});
var Person = DefineMap.extend("Person", {
id: { type: "number", identity: true },
name: "string",
pet: Pet
});

var store = fixture.store([{
id: 1,
name: "Dorothy",
pet: {
name: "Max"
}
}], new QueryLogic(Person));

fixture('/api/persons/{id}', store);

var xhr = new XMLHttpRequest();
xhr.addEventListener('load', function() {
var data = JSON.parse(this.responseText);
var xhr2 = new XMLHttpRequest();

xhr2.addEventListener('load', function() {
var data = JSON.parse(this.responseText);
assert.equal(data.pet.name, "Max", "Still have the Pet type");
done();
});
xhr2.open('PUT', '/api/persons/1', true);
xhr2.send(data);

});
xhr.open('GET', '/api/persons/1', true);
xhr.send();
});

if ("onabort" in XMLHttpRequest._XHR.prototype) {
QUnit.test('fixture with timeout aborts if xhr timeout less than delay', function(assert) {
var done = assert.async();
Expand Down Expand Up @@ -2009,7 +2050,7 @@ if ("onabort" in XMLHttpRequest._XHR.prototype) {
return {};
});

teardown();
teardown();
});

testHelpers.dev.devOnlyTest("Works with steal-clone", function (assert) {
Expand All @@ -2034,6 +2075,3 @@ if ("onabort" in XMLHttpRequest._XHR.prototype) {
var done = assert.async();
});
} // END onabort check



0 comments on commit fa001c5

Please sign in to comment.