Registry / testing / parse-mockdb

parse-mockdb

JSON →
library0.4.0jsnpmunverified

parse-mockdb provides a mocked RESTController for the Parse JavaScript SDK, specifically compatible with version `2.0+`. It is primarily designed for unit testing Parse-dependent applications by allowing developers to simulate Parse backend operations (CRUD, queries, relations) locally without requiring an actual Parse Server instance. The current stable version is 0.4.0, which targets Parse JS SDK 2.x. While it supports many core Parse features like basic CRUD, various query operators (e.g., $exists, $in, $regex), and Parse.Relation, it currently lacks support for Parse class-level permissions, ACLs, and special classes like Parse.User or Parse.Role. The release cadence appears to be driven by breaking changes and updates to align with the Parse SDK, with significant breaking changes in versions 0.3.0 and 0.4.0.

npm install parse-mockdb
INSTALL
IMPORT
SIG · PARSE-MOCKDB
P
parse-mockdb
testingjavascriptv0.4.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ParseMockDB
const ParseMockDB = require('parse-mockdb');
import ParseMockDB from 'parse-mockdb';
Primarily designed for CommonJS usage, often in Node.js testing environments. ESM import syntax is not officially supported and may lead to issues.
mockDB
ParseMockDB.mockDB(Parse);
const { mockDB } = require('parse-mockdb'); mockDB(Parse);
The `mockDB` and other utility functions are methods on the `ParseMockDB` object, not standalone named exports.
Parse
const Parse = require('parse-shim');
const Parse = require('parse');
The library internally uses `parse-shim` for mocking, which is often used as a direct `require` in test setups alongside `parse-mockdb`.

This quickstart demonstrates how to set up `parse-mockdb`, mock the Parse SDK, perform basic CRUD operations, and then clean up the mock database. It highlights the typical workflow for unit testing Parse applications.

'use strict'; const Parse = require('parse-shim'); const ParseMockDB = require('parse-mockdb'); // Initialize Parse (e.g., required for some SDK operations) Parse.initialize('appId', 'jsKey', 'masterKey'); Parse.serverURL = 'http://localhost:1337/parse'; // Or any placeholder ParseMockDB.mockDB(Parse); // Mock the Parse RESTController // Perform saves, queries, updates, deletes, etc... using the Parse JS SDK async function testParseOperations() { const MyObject = Parse.Object.extend('MyObject'); const myObject = new MyObject(); myObject.set('key', 'value'); await myObject.save(); console.log('Object saved with id:', myObject.id); const query = new Parse.Query(MyObject); query.equalTo('key', 'value'); const results = await query.find(); console.log('Found objects:', results.length); } testParseOperations().then(() => { ParseMockDB.cleanUp(); // Clear the Database ParseMockDB.unMockDB(); // Un-mock the Parse RESTController console.log('MockDB cleaned up and un-mocked.'); });
Debug
Known issues
breakingVersion 0.4.0 is a breaking change, specifically targeting the 2.x series of the Parse JS SDK. If you are using Parse JS SDK 1.6+, you must pin your `parse-mockdb` dependency to the `v0.3.x` release to maintain compatibility.
fix
For Parse JS SDK 1.6+, use `npm install parse-mockdb@~0.3.0`. For Parse JS SDK 2.x+, use `npm install parse-mockdb`.
affects: >=0.4.0
breakingWith v0.3.0, the `mockDB()` function now requires you to pass a reference to the Parse SDK instance you wish to mock. This was a significant change from previous versions.
fix
Update calls from `ParseMockDB.mockDB()` to `ParseMockDB.mockDB(Parse);` ensuring `Parse` is your initialized Parse SDK object.
affects: >=0.3.0
breakingAs of v0.3.0, the `ParseMockDB` object is no longer patched onto the `Parse` module itself. You can no longer access it via `Parse.MockDB`.
fix
Always load `parse-mockdb` explicitly using `const ParseMockDB = require('parse-mockdb');` and refer to `ParseMockDB` directly.
affects: >=0.3.0
breakingThe `ParseMockDB.promiseResultSync` method was removed in v0.3.0, impacting tests or code that relied on synchronous promise resolution within the mock.
fix
Refactor code to use standard asynchronous promise handling (e.g., `async/await` or `.then/.catch`) instead of the removed synchronous utility.
affects: >=0.3.0
gotchaThe library's completeness section indicates several unimplemented features, including Parse class-level permissions, ACLs (row-level permissions), and special classes like `Parse.User` or `Parse.Role`. Tests relying on these features will not behave correctly with `parse-mockdb`.
fix
Structure tests to avoid dependencies on unimplemented features, or consider integrating with a full Parse Server for tests requiring these advanced functionalities.
affects: All
Errors
Common errors & fixes
TypeError: ParseMockDB.mockDB is not a function
Attempting to call `mockDB` without passing the Parse SDK instance after v0.3.0, or `ParseMockDB` was accessed incorrectly.
fix
Ensure `const Parse = require('parse-shim');` and then call `ParseMockDB.mockDB(Parse);`.
ReferenceError: Parse is not defined
The Parse SDK (or `parse-shim`) was not imported or initialized before being passed to `ParseMockDB.mockDB()`.
fix
Add `const Parse = require('parse-shim');` at the top of your test file or ensure Parse is globally available if that's your setup.
Error: "undefined" is not a valid class name.
This error often occurs when trying to use `Parse.Object.extend` or `new Parse.Query` without a properly initialized Parse environment, which `parse-mockdb` hooks into.
fix
Ensure `Parse.initialize()` is called with placeholder values (appId, jsKey, masterKey) before mocking, as the Parse SDK sometimes requires this even when mocking.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
parserequiredPeer dependency for the Parse JavaScript SDK, which this library mocks. Specifically requires ^2.0.0.
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
parse-mockdb — npm install parse-mockdb · libregistry