Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Where do I place a simple direct assert without the server/emit round-trip? #97

Open
dandv opened this Issue · 5 comments

2 participants

@dandv

Laika is nice but honestly the whole emit roundtrip is a bit too much for simple tests. Where can I place just asserts to perform unit tests? I have this in server/myfunc.js:

myFunc = function (argument) {
  return argument * 2;
}

Then in tests/ I have the official example, with some asserts but they all fail with reference errors:

//tests/posts.js
var assert = require('assert');

suite('Posts', function() {
  test('in the server', function(done, server) {

    // assert.equal(myFunc(2), 4);  // ReferenceError: myFunc is not defined

    server.eval(function() {
      Posts.insert({title: 'hello title'});
      // assert.equal(myFunc(2), 4);  // ReferenceError: assert is not defined
      var docs = Posts.find().fetch();
      emit('docs', docs);
    });

    server.once('docs', function(docs) {
      assert.equal(docs.length, 1);
      // assert.equal(myFunc(2), 4);  // ReferenceError: myFunc is not defined
      done();
    });
  });
});
@arunoda
Owner

Yep. emit is not a good pattern. That's why we introduced evalSync

@dandv

Can it be made as simple as this?

suite('myFunc', function() {
  test('in the server', function(done, server) {
    assert.equal(myFunc(2), 4);
    done();  // needs to be documented - see issue #100
  });
});

I'm just trying to test some library functions that don't require the server or the client eval - the functions are independent. But I can't call these functions from an assert - see issue #98. What is the correct pattern for simple cases like the above?

@arunoda
Owner

If that's a library. You can directly require it. Let's say your library is inside lib/abc.js. Do it with require('./lib/abc.js)

@dandv

New Laika's interface looks sweet! :+1:

image

@arunoda
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.