A Karma plugin for testing Parse Cloud Code.

npm install karma-parse-sinon
1 downloads in the last week
3 downloads in the last month

karma-parse-sinon Build Status

A Karma plugin for unit testing Parse Cloud Code.




The main functionality that this package provides is the Parse.Cloud.Simulator.runFunction method:

 * Simulates the execution of a Cloud Code function.
 * @method runFunction
 * @param {String} functionName The name of the Cloud Code function to execute.
 * @param {Object} [params] The parameters object sent to the function by the client.
 * @param {Parse.User} [user] The Parse.User that is making the request.
 * @return {Object} The response object.
 *   @param {Function} success A sinon spy for the response success method.
 *   @param {Function} error A sinon spy for the response error method.
function runFunction(functionName, params, user)

Given a Parse Cloud Code function:

Parse.Cloud.define('hello', function(request, response) {
    if (request.params.helpful == false || request.user.get('disposition') == 'rude') {
        response.error('Go away.');
    } else {
        response.success('Hello world!');

You can use the Parse.Cloud.Simulator to test the function:

describe('hello', function () {

    it('says hi', function () {
        var response = Parse.Cloud.Simulator.runFunction('hello');

        response.success.args[0][0].should.equal('Hello world!');

    it('errors when feeling unhelpful', function () {
        var response = Parse.Cloud.Simulator.runFunction('hello', {
            helpful: false

        response.error.args[0][0].should.equal('Go away.');

    it('errors when user is rude', function () {
        var user = new Parse.User();
        user.set('disposition', 'rude');

        var response = Parse.Cloud.Simulator.runFunction('hello', {}, user);

        response.error.args[0][0].should.equal('Go away.');

npm loves you