Closed caio-ribeiro-pereira closed 10 years ago
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.
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 !!
Awesome. Yep, I'll help.
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...
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!