How to use the node-mocks-http.createResponse function in node-mocks-http

To help you get started, we’ve selected a few node-mocks-http examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github universal-vue / uvue / packages / @uvue / vue-cli-plugin-ssr / uvue / StaticGenerate.js View on Github external
createRequestContext(url) {
    // Fake IncomingRequest
    const req = httpMocks.createRequest({
      method: 'GET',
      url,
    });

    // Fake ServerResponse
    const res = httpMocks.createResponse();
    res.__body = '';
    res.write = chunk => {
      res.__body += chunk;
    };
    res.end = data => {
      if (data) {
        res.__body = data;
      }
    };

    return {
      url,
      req,
      res,
      redirected: false,
      statusCode: 200,
github Strider-CD / strider / test / unit / test_middleware.js View on Github external
it('should fallthrough if all params are present', function () {
      var mockReq = httpMocks.createRequest({
        body: {
          email: 'user@email.com',
          name: 'New Guy'
        }
      });
      var mockRes = httpMocks.createResponse();

      middleware.requireBody(['email', 'name'])(mockReq, mockRes, function () {
        mockRes.statusCode = 200;
      });

      mockRes.statusCode.should.eql(200);
    });
github solid / oidc-auth-manager / test / unit / login-consent-request.js View on Github external
it('should be false if params has no client id', () => {
      let params = {}
      let response = HttpMocks.createResponse()
      let opAuthRequest = {
        host: {}
      }

      let request = new LoginConsentRequest({ params, response, opAuthRequest })

      expect(request.isLocalRpClient(undefined)).to.be.false()
    })
github punchcard-cms / punchcard / tests / applications.js View on Github external
test('Create new secret', t => {
  const req = _.cloneDeep(reqObj);
  req.method = 'POST';
  req.headers.referrer = '/applications/1';
  req.session.form.applications.edit.id = 1;

  const request = httpMocks.createRequest(req);

  const response = httpMocks.createResponse({ eventEmitter: EventEmitter });
  const resp = applications.routes.secret(request, response, next);
  response.render();

  return response.on('end', () => {
    t.is(response.statusCode, 302, 'Should be a 302 response');
    t.is(response._getRedirectUrl(), '/applications/1', 'should redirect to edit url');

    return resp.then(res => {
      t.not(res, dbmocks.rows[0]['client-secret'], 'should be a new client secret');
    });
  });
});
github matheuslc / shorts / test / url / shortUrlController.spec.js View on Github external
it('Should throw an error if url does not exist', () => {
    let request = httpMocks.createRequest({
      method: 'POST',
      body: {}
    });

    let response = httpMocks.createResponse({
      eventEmitter: events.EventEmitter
    });

    expect(() => {
      Controller.createShortUrl(request, response);
    }).to.throw(Error);
  });
github punchcard-cms / punchcard / tests / users.js View on Github external
test.cb('Single user route - bad id', t => {
  const req = _.cloneDeep(reqObj);
  req.url = '/users/1000';
  req.params.id = 1000;

  const request = httpMocks.createRequest(req);

  const response = httpMocks.createResponse({ eventEmitter: EventEmitter });
  const resp = users.routes.one(request, response, next);

  response.on('end', () => {
    t.is(response.statusCode, 200, 'Should be a 200 response');

    return resp.then(res => {
      t.is(res.status, 404, 'should have 404 status');
      t.end();
    });
  });
  response.render();
});
github alex94cp / jsonapify / test / middleware / modify.js View on Github external
field: common.createAccessor(),
			output: common.createAccessor(),
		};
		resource = new Resource(model, {
			type: 'test',
			field: {
				value: accessors.field,
				nullable: true,
			},
			output: {
				value: accessors.output,
				nullable: true,
			},
		});
		Runtime.addResource('ModifyResource', resource);
		res = httpMocks.createResponse();
	});
github sevcsik / node-couchdb-model / tests / restapi.spec.js View on Github external
' on a findOne request', function(done) {
			var request = httpMocks.createRequest({
				method: 'GET',
				url: '/by_slug/test_article_one_slug'			
			});

			var response = httpMocks.createResponse();

			Q.all([
				model.findOneBySlug('test_article_one_slug'),
				Q.delay(1000)
			]).then(function(result) {
				result = result[0];
				response.statusCode.should.equal(200, 'status code');

				var responseData = JSON.parse(response._getData());

				responseData.should.deep.equal(result.toVO());
			}).then(function() {
			   done();
			}, function(error) {
				done(error);
			});
github NERC-CEH / datalab / code / workspaces / infrastructure-api / src / controllers / stackController.spec.js View on Github external
it('should process a valid request', () => {
      const response = httpMocks.createResponse();

      return stackController.createStack(request, response)
        .then(() => {
          expect(response.statusCode).toBe(201);
        });
    });

node-mocks-http

Mock 'http' objects for testing Express, Next.js and Koa routing functions

MIT
Latest version published 2 months ago

Package Health Score

92 / 100
Full package analysis