Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for testing rejected Cloud triggers #5

Open
danepowell opened this issue Sep 10, 2018 · 0 comments
Open

Example for testing rejected Cloud triggers #5

danepowell opened this issue Sep 10, 2018 · 0 comments

Comments

@danepowell
Copy link

danepowell commented Sep 10, 2018

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();
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant