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

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

Open
dandv opened this issue Feb 20, 2014 · 5 comments
Open

Comments

@dandv
Copy link
Contributor

dandv commented Feb 20, 2014

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
Copy link
Owner

arunoda commented Feb 20, 2014

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

@dandv
Copy link
Contributor Author

dandv commented Feb 20, 2014

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
Copy link
Owner

arunoda commented Feb 21, 2014

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
Copy link
Contributor Author

dandv commented Apr 2, 2014

New Laika's interface looks sweet! 👍

image

@arunoda
Copy link
Owner

arunoda commented Apr 2, 2014

Thanks :)


Arunoda Susiripala

@arunoda http://twitter.com/arunoda
http://gplus.to/arunodahttps://github.com/arunoda
http://www.linkedin.com/in/arunoda

On Wed, Apr 2, 2014 at 6:47 AM, Dan Dascalescu notifications@github.comwrote:

New Laika's interface looks sweet! [image: 👍]

[image: image]https://cloud.githubusercontent.com/assets/33569/2586584/83a718dc-ba04-11e3-9b95-c9a8da23f332.png


Reply to this email directly or view it on GitHubhttps://github.com//issues/97#issuecomment-39279780
.

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