1

I'm starting a project on Meteor and i'm trying to use intern js for my tests. So, I have a mongoDB collection and i'm trying to run tests on it.

I have this statement on the file I want to test

this.Teams = new Meteor.Collection('teams');

And i get this error at this line :

ReferenceError : Meteor is not defined

Is there a way to solve this problem ?

Regards

TLR
  • 577
  • 3
  • 8
  • 24

2 Answers2

0

Somehow I managed to test Meteor application with TheIntern.js.

Though it is as per my need. But still I think it may lead someone to the right direction and I am sharing what I have done to resolve this issue.

There is a execute function which allows us to run JS code thorugh which we can access browsers window object and hence Meteor also.

Want to know more about execute

This is how my test suite looks for Functional Testing

define(function (require) {
    var registerSuite = require('intern!object');
    var assert = require('intern/chai!assert');
    registerSuite({
        name: 'index',

        'greeting form': function () {
            var rem = this.remote;
            return this.remote
                .get(require.toUrl('localhost:3000'))
                .setFindTimeout(5000)
                .execute(function() {
                        console.log("browser window object", window)
                        return Products.find({}).fetch().length
                    })
                .then(function (text) {
                    console.log(text)
                    assert.strictEqual(text, 2,
                        'Yes I can access Meteor and its Collections');
                });
        }
    });
});

To know more, this is my gist

Note: I am still in very early phase with this solution. I don't know whether I can do complex testing with this or not. But i am pretty much confident about it.

Harpreet Singh
  • 2,651
  • 21
  • 31
-1

You need use a special framework for writing unit-test for meteor app. See Meteor test driven development

Note: 'Meteor.Collection' is deprecated namespace. Use 'Mongo.Collection'

Community
  • 1
  • 1
anstarovoyt
  • 7,956
  • 2
  • 27
  • 35
  • So there is no way I can use Intern js to test my app ? – TLR Apr 13 '15 at 12:38
  • 1
    This is absolutely not true. You can test any application written using any framework with Intern. – C Snover Apr 13 '15 at 16:07
  • 2
    How then ? I didn't see any examples on internet – TLR Apr 14 '15 at 07:26
  • Since I discovered the build method in Meteor, I think it's possible to use internjs. Indeed, when you build your app, you use node to run it instead of meteor. I'll do some tests and keep you guys in touch – TLR Jul 01 '15 at 13:31