Skip to content

Commit

Permalink
Added tests for Instance
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Apr 22, 2015
1 parent 7cf37ca commit 6c84643
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/Instance.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Instance.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion lib/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class Instance<TDocument, TInstance> {
var isArray = Array.isArray(collection);
var results: any = isArray ? [] : {};

_.each(collection, (value: T, key) => {
_.each(collection,(value: T, key) => {
if (predicate.call(this, value, key)) {
if (isArray) results.push(value);
else results[key] = value;
Expand All @@ -261,6 +261,22 @@ class Instance<TDocument, TInstance> {

return results;
}

/**
* Gets the JSON representation of this instance
* @returns {TDocument}
*/
toJSON(): TDocument {
return this.document;
}

/**
* Gets a string representation of this instance
* @returns {String}
*/
toString(): string {
return JSON.stringify(this.document, null, 2);
}
}

export = Instance;

0 comments on commit 6c84643

Please sign in to comment.