sudo npm install -g laika
$ mongod --smallfiles --noprealloc --nojournal
$ meteor create meteor-laika
// collections/posts.js Posts = new Meteor.Collection('posts');
//tests/posts.js var assert = require('assert'); suite('Posts', function() { test('in the server', function(done, server) { server.eval(function() { Posts.insert({title: 'hello title'}); var docs = Posts.find().fetch(); emit('docs', docs); }); server.once('docs', function(docs) { assert.equal(docs.length, 1); done(); }); }); });
server.eval(function() { Posts.insert({title: 'hello title'}); // var docs = Posts.find().fetch(); // emit('docs', docs); // });
server.once('docs', function(docs) { // assert.equal(docs.length, 1); // , done(); // });
$ laika
test('using both client and the server', function(done, server, client) { server.eval(function() { Posts.find().observe({ added: addedNewPost // , , addedNewPost }); function addedNewPost(post) { emit('post', post); // "post" post ( ) } }).once('post', function(post) { // "post" assert.equal(post.title, 'hello title'); // , done(); // }); client.eval(function() { Posts.insert({title: 'hello title'}); // }); });
test('using two client', function(done, server, c1, c2) { c1.eval(function() { Posts.find().observe({ added: addedNewPost // }); function addedNewPost(post) { emit('post', post); // , "post" } emit('done'); // "done" }).once('post', function(post) { assert.equal(post.title, 'from c2'); // , , done(); }).once('done', function() { c2.eval(insertPost); // insertPost }); function insertPost() { Posts.insert({title: 'from c2'}); // ( , ), } });
Source: https://habr.com/ru/post/213171/
All Articles