plasmapower / assert-request Goto Github PK
View Code? Open in Web Editor NEWAssert responses to HTTP requests in Node.JS
License: MIT License
Assert responses to HTTP requests in Node.JS
License: MIT License
A cookies mixin could be very helpful in some cases in simplifying use cases of the header mixin.
I really like the idea of this. But I can't get it to work (Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
).
I would really appreciate a whole lot more of examples and may be links to projects that are already using it.
$ cat test_app.js
/* eslint-env node,mocha */
var express = require('express');
var app = express();
app.post('/', function (req, res) {
res.json({
'response_type': 'ephemeral',
'text': 'hi there\nhi\n'
});
});
var AssertRequest = require('assert-request');
var request = AssertRequest(app.listen());
describe('basic', function () {
it('json.post', function () {
return request.post('/', {
body: { 'key': 'value' },
json: true
})
.type('application/json')
.status(200)
.json({
'response_type': 'ephemeral',
'text': 'hi there\nhi\n'
});
});
});
json: true
in request will automatically encode the sending and receiving body.
One possible fix is to check if (typeof res.body === 'object')
in mixins/json.js but I'm not sure its the best solution so havn't submitted a PR.
Is it possible to set request headers somehow?
With superagent and supertest you use .set()
https://github.com/visionmedia/supertest/blame/d0c14578cd51eab83019ee7d5a46d21a2ae5b170/Readme.md#L48-L60
TypeError: AssertRequest(...).post(...).set is not a function
TypeError: AssertRequest(...).set is not a function
This is supported by supertest
request.get('/foo').assert(res => myPromiseAssertion(res))
Should be a simple change to something like:
'use strict';
const assert = require('assert');
module.exports = {
assert: function (fn) {
return this.then(function (res) {
return Promise.resolve(fn(res))
.then(value => assert(value))
.then(() => res);
});
}
};
Please consider to make the license more clear adding a LICENSE file at the root of the repo or mentioning it in a "license" section in the README.
I know that package.json
has it, but I think that one of those solutions would make it very visible.
Thanks for the module and release it under MIT
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.