Responsive Ad Area

Share This Post

test

TypeError: http is not a function in jest framework

i am using react js as my javascript framework, where i have installed jest and using pact(CDC) for unit test cases and while i run the command “npm run test” the spec.js file is failing and throwing an error like this
“TypeError: http is not a function”
i am stuck here please help
for better understanding i am uploading the screen shot of the image as well.
i need this to be fixed asap please help me out with better solution.

THIS IS CRITERIA-MANAGEMENTCOMPONENT.SPEC.JS file

const path = require('path')
const pact = require('pact')
const API_PORT =  process.env.API_PORT || 9123
const {
  fetchProviderData, getCriteriaManagementComponent, criteriaManagementComponent
} = require('../client')

// Configure and import consumer API
// Note that we update the API endpoint to point at the Mock Service
const LOG_LEVEL = process.env.LOG_LEVEL || 'WARN'

const provider = pact({
  consumer: 'Web Login',
  provider: 'Web API',
  port: API_PORT,
  log: path.resolve(process.cwd(), 'logs', 'pact.log'),
  dir: path.resolve(process.cwd(), 'pacts'),
  logLevel: LOG_LEVEL,
  spec: 2
})

describe('Started Testing Pact', () => {

  beforeEach((done) => {
    return provider.setup().then(() => done());
  });

  afterEach((done) => {
    return provider.finalize().then(() => done())
  })

  describe('criteriaManagement', () => {

    beforeEach(() => {
      let criteriaManagement = {
        uponReceiving: 'wrong criteriaManagement',
        state: 'Code OK',
        withRequest: {
          method: 'GET',
          path: '/api/criteria',
        },
        willRespondWith: {
          status: 200,
          headers: {
            'Content-Type': 'application/json; charset=utf-8'
          },
          body: {

                code: "string",
                context: {},
                message: "string",
                payload: [
                  {
                    country: "string",
                    createdBy: "string",
                    displayOrder: 0,
                    id: "string",
                    lastModifiedBy: "string",
                    name: "string",
                    translations: {},
                    warehouse: "string"
                  }
                ]      
          }
        }
      };
      return provider.addInteraction(criteriaManagement)
    })

    afterEach(() => {
      return provider.verify()
    })

    it('Login test', done => {
      criteriaManagementComponent().then((res) => {
        expect(res.code).not.toBeNull();
        expect(res.context).toBeDefined();
        expect(res.message).not.toBeNull();
        expect(res.payload.country).not.toBeNull();
        expect(res.payload.createdBy).not.toBeNull();
        expect(res.payload.displayOrder).toBe(0);
        expect(res.payload.id).not.toBeNull();
        expect(res.payload.lastModifiedBy).not.toBeNull();
        expect(res.payload.translations).toBeDefined();
        expect(res.payload.name).not.toBeNull();
        expect(res.payload.warehouse).not.toBeNull();


      });
      done();
    })
  });
})

THIS IS CLIENT.JS FILE FOR CRITERIA-MANAGEMENTCOMPONENT.SPEC.JS FILE

const request = require('superagent')
const API_HOST = process.env.API_HOST || 'http://localhost'
const API_PORT = process.env.API_PORT || 9123
const API_ENDPOINT = `${API_HOST}:${API_PORT}`

// Fetch provider data
const fetchProviderData = (submissionDate) => {
  return request
    .get(`${API_ENDPOINT}/provider`)
    .query({ validDate: submissionDate })
    .then((res) => {
      console.log("Response :: ", res.body);
      return {
        count: 100 / res.body.count,
        date: res.body.date
      }
    })
}

const getCriteriaManagementComponent = (accessToken, expiresIn) => {
  return request
    .post(`${API_ENDPOINT}/api/criteria`)
    .then((res) => {
      return {
        code : res.body.code
      }
    })
}

const criteriaManagementComponent = () => {
    // const request = require('request')
  console.log("End Point =========> ", `${API_ENDPOINT}/api/criteria`)
  return request.get(`${API_ENDPOINT}/api/criteria`).then((res) => {
    return {
      code : res.body.code,
      context:res.body.context,
      message:res.body.message,
      payload:res.body.payload,
      profile:res.body.payload.profile,

      successful : res.body.successful
    }
  })
};

module.exports = {
  fetchProviderData, getCriteriaManagementComponent, criteriaManagementComponent
}


TypeError: http is not a function in jest framework
TypeError: http is not a function in jest framework
test
{$excerpt:n}

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar