vendredi 9 novembre 2018

Node-scheduler error after implement test

After I have successfully implemented one of methods to fetch some data and run test

Code:

const fetchData = async (url) => {
  const response = await axios.get(url);
  const contentType = response.headers['content-type'];

  if (typeof response.data === 'object') {
    return JSON.stringify(response.data);
  }
    throw new Error('Content-Type is unrecognized');
};

module.exports = fetchData;

And test:

describe('fetchData', () => {

  it('should return json string response data on successful request', async () => {

    const responseData = await fetchData(url);

    const expectedData = JSON.stringify({ key1: 'value1' });

    assert.deepEqual(responseData, expectedData, 'Response data doesn\'t match');
  });

However, I wanted to implement scheduling to my method. I implemented in by using node-scheduler npm module.

After my modification

scheduler.scheduleJob({ start: startTime, end: endtTime }, async () => {
      const fetchData = async (url) => {
      const response = await axios.get(url);
}

Tests are failing immadietly, furthermore I noticed that error log is going continuously, therefore I have to kill test.

Does anyone have an idea why adding simple scheduler makes my error not working? I am using:

  • Node v.8.11.4
  • chai-as-promised
  • nock

Aucun commentaire:

Enregistrer un commentaire