Parse SDK Mocked Database

0.4.0 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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.');
});

view raw JSON →