Meteor change consts during unit-test

#1

I have wrote simple unit test. The part of it is:

import { Meteor } from 'meteor/meteor';
import { expect } from 'chai';
import { Mongo } from 'meteor/mongo';
import { Notifications } from './../notifications';

const nOne =  {
    userId: 445566,
    post: {
        _id: 'postId',
        image: 'image URL',
        text: 'text of the post',
        company_name: 'text',
        company_source: 'someURL'
    },
    coords: {latitude:59, longitude:30}
}

if (Meteor.isServer) {
    describe ('notifications ', function () {

        beforeEach(function() {
            Notifications.remove({});
        });


      
        it ('some test', function () {

            Meteor.server.method_handlers['notifications.add'].apply({},[nOne]);
            
        });


    })
}

And the problem is that nOne.coords before the test is {latitude:59, longitude:30}
but after call meteor method it [{latitude:59, longitude:30}] - an array;

how is it possible that Meteor method change const. And change it from Object to [Object] ?

#2

No sure what code is changing this, but object properties and array items ‘can’ be changed. This is not a Meteor thing, but an Ecmascript thing.

#3

Indeed. You just cannot reassign something that has been declared const.

In that regard, use of the const keyword is a bit … unfortunate.

1 Like
#4

But how Meteor handler can change the variable? I just apply it