ABC
ABC

Reputation: 1467

Testing packages that rely on Meteor settings

I'm trying to test my package that needs a value from Meteor.settings. But when I start the test, I get this error:

Exception while invoking method 'sendData' TypeError: Cannot read property 'appKey' of undefined

My test:

 it('sends event data in proper form', function () {
    Meteor.settings = {
      myApp: {
        appKey: 'thisisafakeappkey',
      },
    };

    const post = sinon.stub(HTTP, 'post');

    trackEvent(event, data, user);
    HTTP.post.restore();
}

The method:

Meteor.methods({
    'sendData'({ payload }) {
      const appKey = Meteor.settings.myapp.appKey;
      if (!appKey) throw new Meteor.Error('No app key found in Meteor.settings.');

      const withAppKey = Object.assign({ appKey }, payload);

      HTTP.post(getRemoteUrl(), {
        data: withAppKey,
      }, (err, res) => {
        if (err) console.log('err', err);
        else console.log('res', res);
      });
    },
  });

Upvotes: 3

Views: 208

Answers (1)

Samuel
Samuel

Reputation: 5713

If you use meteor 1.3 you could at least run a full app test with:

meteor test --full-app --settings my.settings.json --driver-package <driverpackage>

https://guide.meteor.com/testing.html

Upvotes: 3

Related Questions