Skip to content

Commit

Permalink
fixed liniting and added formatting options test
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-meshbey committed Apr 11, 2021
1 parent b8505ee commit c92ff22
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/model/modelToJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function toJson(model, optIn) {
pick: null,
omitFromJson: model.$omitFromJson() || null,
cloneObjects: modelClass.cloneObjectAttributes,
format: optIn && optIn.format
format: optIn && optIn.format,
};

let json = toExternalJsonImpl(model, opt);
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/model/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,27 @@ describe('Model', () => {
expect(calls).to.equal(1);
});

it('should call $formatJson with formatting options', () => {
let calls = 0;
let json = { a: 1 };
let opt = { c: 2 };

Model1.prototype.$formatJson = (jsn, o) => {
++calls;
expect(jsn).to.eql(json);
expect(o).to.eql(opt);
jsn.b = 2;
return jsn;
};

let model = Model1.fromJson(json);
let output = model.$toJson({ format: opt });

expect(output.a).to.equal(1);
expect(output.b).to.equal(2);
expect(calls).to.equal(1);
});

it('should call $toJson for properties of class Model', () => {
let Model2 = createModelClass();

Expand Down

0 comments on commit c92ff22

Please sign in to comment.