Meteor 1.3 - How to test client-side Accounts.createUser() with Chimp

Hey guys, I’m new at testing so feel free to point out the best way to do this…

The Goal: To test that the client CANNOT create users, even from the console… and to learn about testing general scenarios like this.

What I tried: I’m using Chimp:

it('Cannot create new Accounts from the client side', function () {
  var error = null;
  Accounts.createUser({email:'testemail@example.com', password:'averybadpassword'}, function (err) {
    error = err;
  });
  expect(error).to.be.a('error');
});

The Problem: “Uncaught ReferenceError: Accounts is not defined”

Chimp won’t let me use import statements and xolvio:backdoor is only for server side stuff… but I need this to execute from the client side.

So, any ideas on how to test something like this?

try:

it('Cannot create new Accounts from the client side', function () {
  var error = client.executeAsync(function(done) {
    Accounts.createUser({email:'testemail@example.com', password:'averybadpassword'}, function (err) {
      done(err);
    });
  });

  expect(error).to.be.a('error');
});

Brilliant! Thanks :slight_smile:

I’ll have to look more closely at the WebdriverIO api… There’s more to it than I realized.

In case it helps anyone else, here’s the final working code snippet from the Chimp test:

it('Cannot create new Accounts from the client side', function () {
  var error = browser.executeAsync(function(done) {
    Accounts.createUser({email:'test@example.com', password:'abc123'}, function (err) {
      done(err);
    });
  });
  
  expect(error.value.reason).to.contain('forbidden');
});