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

Running Client before Server #116

Closed
caio-ribeiro-pereira opened this issue Apr 5, 2014 · 3 comments
Closed

Running Client before Server #116

caio-ribeiro-pereira opened this issue Apr 5, 2014 · 3 comments

Comments

@caio-ribeiro-pereira
Copy link

Hi again!

Is there a way to simulate a client execution first and server assert after?

For exemple, only clients can publish a post, so it'll be something like...

var assert = require("assert");

suite("Post", function() {  
  test("publish a new post", function(done, server, client) {
    client.eval(function() {
         Post.insert({message: "hi!"});
    });
    server.eval(function() {
      Post.find().observe({
       added: function(doc) {
        emit("added", doc);
       }
    });
    server.once("added", function(doc) {
        assert.equal(doc.message, "hi!");
      done();
    });
  });
});

I have some functions which only client can execute (because it needs a logged user), and I don't know how to simulate this kind of test.

I will wait some answer, Thanks!

@arunoda
Copy link
Owner

arunoda commented Apr 7, 2014

You can do it with our evalSync API. see:

var assert = require("assert");

suite("Post", function() {  
  test("publish a new post", function(done, server, client) {
    client.evalSync(function() {
       Post.insert({message: "hi!"}, function() {
        emit('return');
       });
    });

    var docs = server.evalSync(function() {
      var docs = Post.find().fetch();
      emit('return', docs);
    });

    assert.equal(docs[0].message, "hi!");
    done();
  });
});

And for the login, you can create a user on every test. Like below.

client.evalSync(function() {
  Accounts.createUser({username: "arunoda", password, "abc"}, function() {
    emit('return');
  });
});

may be you can create a common function for this, where you can use in any testCase you want.

@caio-ribeiro-pereira
Copy link
Author

This is my new book about Meteor https://casadocodigo.refersion.com/l/d88.3525 (Brazilian portuguese) today is on beta version, but in the full version it will have a chapter about testing using laika and thats why I requested a help here :)

Thanks @arunoda !!

@arunoda
Copy link
Owner

arunoda commented Apr 7, 2014

Awesome. Yep, I'll help.

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

2 participants