{"id":16479,"library":"parse-mockdb","title":"Parse SDK Mocked Database","description":"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.","status":"active","version":"0.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/Hustle/parse-mockdb","tags":["javascript","parse","parsesdk","mock","unit-testing"],"install":[{"cmd":"npm install parse-mockdb","lang":"bash","label":"npm"},{"cmd":"yarn add parse-mockdb","lang":"bash","label":"yarn"},{"cmd":"pnpm add parse-mockdb","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for the Parse JavaScript SDK, which this library mocks. Specifically requires ^2.0.0.","package":"parse","optional":false}],"imports":[{"note":"Primarily designed for CommonJS usage, often in Node.js testing environments. ESM import syntax is not officially supported and may lead to issues.","wrong":"import ParseMockDB from 'parse-mockdb';","symbol":"ParseMockDB","correct":"const ParseMockDB = require('parse-mockdb');"},{"note":"The `mockDB` and other utility functions are methods on the `ParseMockDB` object, not standalone named exports.","wrong":"const { mockDB } = require('parse-mockdb'); mockDB(Parse);","symbol":"mockDB","correct":"ParseMockDB.mockDB(Parse);"},{"note":"The library internally uses `parse-shim` for mocking, which is often used as a direct `require` in test setups alongside `parse-mockdb`.","wrong":"const Parse = require('parse');","symbol":"Parse","correct":"const Parse = require('parse-shim');"}],"quickstart":{"code":"'use strict';\nconst Parse = require('parse-shim');\nconst ParseMockDB = require('parse-mockdb');\n\n// Initialize Parse (e.g., required for some SDK operations)\nParse.initialize('appId', 'jsKey', 'masterKey');\nParse.serverURL = 'http://localhost:1337/parse'; // Or any placeholder\n\nParseMockDB.mockDB(Parse); // Mock the Parse RESTController\n\n// Perform saves, queries, updates, deletes, etc... using the Parse JS SDK\nasync function testParseOperations() {\n  const MyObject = Parse.Object.extend('MyObject');\n  const myObject = new MyObject();\n  myObject.set('key', 'value');\n  await myObject.save();\n  console.log('Object saved with id:', myObject.id);\n\n  const query = new Parse.Query(MyObject);\n  query.equalTo('key', 'value');\n  const results = await query.find();\n  console.log('Found objects:', results.length);\n}\n\ntestParseOperations().then(() => {\n  ParseMockDB.cleanUp(); // Clear the Database\n  ParseMockDB.unMockDB(); // Un-mock the Parse RESTController\n  console.log('MockDB cleaned up and un-mocked.');\n});","lang":"javascript","description":"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."},"warnings":[{"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`.","message":"Version 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.","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"Update calls from `ParseMockDB.mockDB()` to `ParseMockDB.mockDB(Parse);` ensuring `Parse` is your initialized Parse SDK object.","message":"With 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.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Always load `parse-mockdb` explicitly using `const ParseMockDB = require('parse-mockdb');` and refer to `ParseMockDB` directly.","message":"As 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`.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Refactor code to use standard asynchronous promise handling (e.g., `async/await` or `.then/.catch`) instead of the removed synchronous utility.","message":"The `ParseMockDB.promiseResultSync` method was removed in v0.3.0, impacting tests or code that relied on synchronous promise resolution within the mock.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Structure tests to avoid dependencies on unimplemented features, or consider integrating with a full Parse Server for tests requiring these advanced functionalities.","message":"The 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`.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure `const Parse = require('parse-shim');` and then call `ParseMockDB.mockDB(Parse);`.","cause":"Attempting to call `mockDB` without passing the Parse SDK instance after v0.3.0, or `ParseMockDB` was accessed incorrectly.","error":"TypeError: ParseMockDB.mockDB is not a function"},{"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.","cause":"The Parse SDK (or `parse-shim`) was not imported or initialized before being passed to `ParseMockDB.mockDB()`.","error":"ReferenceError: Parse is not defined"},{"fix":"Ensure `Parse.initialize()` is called with placeholder values (appId, jsKey, masterKey) before mocking, as the Parse SDK sometimes requires this even when mocking.","cause":"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.","error":"Error: \"undefined\" is not a valid class name."}],"ecosystem":"npm"}