I'm new to testing in Meteor, so I'm worried if my implementation is not going in the right directions. I've written a unit test for my send method which sends a message to a room only if the user is logged in.

import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { Rooms } from '../rooms/rooms.js';
import { Chats } from '../chats/chats.js';
import { assert } from 'meteor/practicalmeteor:chai';
import './chats.js';

if (Meteor.isServer) {
  describe('send chat method', function () {
    let rid;
    before(() => {

      const createUser = Meteor.server.method_handlers['registerUser'];
      let user1 = {
        username: 'user1'
      createUser.apply({}, [user1]);

      let user2 = {
        username: 'user2'
      createUser.apply({}, [user2]);

      // create a room before
      let room = {
        _id: Random.id(),
        h: 'o',
        users: [user1.username, user2.username],
        members: [{
          uh: user1.username,
          isOwner: true,
          isAdmin: true
        }, {
          uh: user2.username
        mc: 0,
        ts: Date.now()
      rid = Rooms.insert(room);
      assert.equal(Rooms.find().count(), 1);

    it('can inset a chat message between two users', () => {
      let msg = {
        msg: 'test message',
        rid: rid,
        u: 'test1',
        ts: new Date(),
        lts: '1848484468',
        incog: '0',
        n: 0
      assert.equal(Chats.find().count(), 1);

I'm not sure if I've written a unit test or an integration test. Do I have to write each module inside the send method as a test, or is this fine?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.