jeudi 7 juillet 2016

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);
      });
    },
  });

Aucun commentaire:

Enregistrer un commentaire