Skip to content

Example for testing rejected Cloud triggers #5

@danepowell

Description

@danepowell

I have a beforeSave trigger that validates objects and throws errors if they fail validation. I want to test that this validation is working as expected.

I can't figure out how to catch the exception / error and prevent Jasmine from failing. Even if I try a structure like this, Jasmine fails early, the catch() block is never even called. I suspect because it's catching the console error thrown by the server backend first. I would have expected the spyOn function to catch that.

// ...
beforeEach((done) => {
    spyOn(console, 'error');
    dropDB()
      .then(done).catch(done.fail);
  });
// ...
it('should reject invalid items', async (done) => {
  // Set up an `item` for saving.
  try {
    await item.save(null, {sessionToken: user.getSessionToken()})
  }
  catch (error) {
    // check error, etc. This is never even called, even though beforeSave is definitely throwing an exception.
    done();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions