mockingoose
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -125,2 +125,30 @@ import mockingoose from '../src/index'; | ||
}) | ||
}); | ||
it('should return object with .toJSON()', () => { | ||
mockingoose.User | ||
.toReturn({ name: 'name' }) | ||
.toReturn({ name: 'a name too' }, 'findOne') | ||
.toReturn({ name: 'another name' }, 'save'); | ||
const mocksString = '{"User":{"find":{"name":"name"},"findOne":{"name":"a name too"},"save":{"name":"another name"}}}'; | ||
const mockString = '{"find":{"name":"name"},"findOne":{"name":"a name too"},"save":{"name":"another name"}}'; | ||
const mocksObject = { | ||
User: { | ||
find: { | ||
name: 'name' | ||
}, | ||
findOne: { | ||
name: 'a name too' | ||
}, | ||
save: { | ||
name: 'another name' | ||
} | ||
} | ||
}; | ||
expect(JSON.stringify(mockingoose)).toBe(mocksString); | ||
expect(JSON.stringify(mockingoose.User)).toBe(mockString); | ||
expect(mockingoose.toJSON()).toEqual(mocksObject); | ||
}) | ||
@@ -127,0 +155,0 @@ }); |
@@ -106,2 +106,5 @@ 'use strict'; | ||
this.__mocks = {}; | ||
}, | ||
toJSON: function toJSON() { | ||
return this.__mocks; | ||
} | ||
@@ -126,2 +129,5 @@ }; | ||
return this; | ||
}, | ||
toJSON: function toJSON() { | ||
return target.__mocks[prop] || {}; | ||
} | ||
@@ -128,0 +134,0 @@ }; |
{ | ||
"name": "mockingoose", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "A Jest package for mocking mongoose models", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
@@ -102,3 +102,3 @@ # Mockingoose | ||
### Operation available: | ||
### Operations available: | ||
@@ -105,0 +105,0 @@ - [x] `find` - for find query |
@@ -95,3 +95,4 @@ import mongoose from 'mongoose'; | ||
__mocks: {}, | ||
resetAll() { this.__mocks = {} } | ||
resetAll() { this.__mocks = {} }, | ||
toJSON() { return this.__mocks } | ||
}; | ||
@@ -116,2 +117,6 @@ | ||
return this; | ||
}, | ||
toJSON() { | ||
return target.__mocks[prop] || {}; | ||
} | ||
@@ -118,0 +123,0 @@ }; |
Sorry, the diff of this file is not supported yet
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
27069
408