parse-mock

Parsejs unit testing library

Usage no npm install needed!

<script type="module">
  import parseMock from 'https://cdn.skypack.dev/parse-mock';
</script>

README

Build Status

Parse Mock

A collection of stubs to ease unit-testing of Parse.com services.

  • Seamless Parse integration. New Mock Object
  • Use with any testing framework
  • Only sinon as a dependency

Brought to you by the DashBouquet team.

Installation

npm install parse-mock --save-dev

Usage

//karma.conf.js

module.exports = function (config) {
  'use strict';
  config.set({
    basePath: '',
    frameworks: ['jasmine', 'sinon'],
    files: [
      'your/app/build.js',
      'src/vendor/parse-mock.js',
      'your/app/**/*.spec.js'
    ],
    browsers: ['Chrome']
  });
};
//sample.spec.js
describe('My parsejs app', function () {

  it('should load some data from parse', function () {
    var stub = Parse.Mock.stubQueryFind(function (options) {
      return [new Parse.Object('User', {name: 'Antony'})]
    });

    expect(getUser()).toBeUndefined();

    loadUser(); //function that invokes Query.find

    expect(getUser()).toBeDefined();
    expect(stub.callCount).toEqual(1); //do assertions on stub object if necessary
  }));

  afterEach(inject(function () {
    Parse.Mock.clearStubs(); //manually dispose of stubs
  }));


});