frisby
frisby copied to clipboard
Documentation
Documentation is lacking for FrisbyJS v2. The README quickly shows howto get(), I managed to post by guessing the second parameter is the post body. Now I am struggling to find howto add headers.
ie: Expected 'TypeError: frisby.get(...).addHeader is not a function I could spend some time getting familiar with the code but I'm lazy :-)
Would be nice to have a globalSetup() documentation for v2.
This made it work:
this.frisby.globalSetup({
request: {
headers: {
"Authorization": "JWT " + json._body.jwt
}
}
});
Re-opening because I do think good docs is still an issue.
@vlucas what approach are you taking on docs?
I am currently trying to use GitBook: https://vlucas.gitbooks.io/frisby/
I planned on pointing the main frisbyjs.com domain there when finished. It's free for open source projects.
It's using a separate repo, right? I find the documentation generate from code way easier to keep in synch with code - like in jsdoc. I guess that for approaching it this way, we would need some CI (travis?) and a place to dump the built doc.
I agree in principle, but I have never seen a pure generated doc file that I have actually really liked and found helpful, with useful examples of usage.
The documentation at http://frisbyjs.com/docs/api/ is using obsolete methods (.create, .expectStatus etc) which cause errors when you are getting started with frisby and pull in the latest stuff (v2). Feels unnecessary. Thanks for a nice tool.
I just pointed the main frisbyjs.com domain to gitbook, so it will point there when it is fully resolved.
The lack of documentation is a real issue here. I have used v1 before and I liked it. Now we're trying out the v2 version but it's a real struggle with the current docs. Is this being worked on or should we try an another alternative?
The docs are actively being worked on. What specifically is lacking that is blocking you?
Please add examples on how to reuse cookies for authenticated sessions. Few APIs will lack authentication.
E.g.:
const apiBase = "some-url";
const user = {
username: "my-name",
password: "*****"
};
const sessionCookieName = "session-cookie-name=";
let sessionId = null;
it("Login and save session successfully", doneCb => {
const frb = frisby.post(`${apiBase}/login`, user);
frb.expect("status", 200);
// validate content of user model
frb.then(resp => {
const cookie = resp.headers.get("set-cookie");
const sidStart = cookie.indexOf(sessionCookieName) + sessionCookieName.length;
const sessionId = cookie.substring(sidStart, cookie.indexOf(";", sidStart));
console.log("SID", sessionId); // FIXME: don't print!
frb.done(done);
});
}
hello, does frisby support async/await?
describe('Posts', function () {
it('should return all posts and first post should have comments', async (done) => {
await frisby.get('http://jsonplaceholder.typicode.com/posts');
frisby.get('http://jsonplaceholder.typicode.com/posts')
.done(done);
});
});
@koooge
Yes.
here is sample code.
const frisby = require('frisby');
describe('should be a teapot', function() {
it('should be a teapot', async () => {
await frisby.get('http://httpbin.org/status/418').expect('status', 418);
return frisby.get('http://httpbin.org/status/200').expect('status', 200);
});
});
Any update on docs? V2 docs are awfully incomplete ... we are probably going to switch to a combo of Mocha/Chai/Supertest because of this
@Archanian Understood. Is there anything specific that you were looking for that you feel is missing?
Something as comprehensive as the docs that used to exist for the previous version would be a start, they were excellent. I can't give you specific examples because I myself know how to use the library pretty well, and have been using it for years. But for new developers on our team it is quite challenging, trying to learn and pick it up is very difficult when the current docs are so minimal.
I just updated the website to list all the assertions and the nested HTTP spec example from the README.md
in the root of this repo. I will continue improving the docs over the next few days.
Awesome, thanks for the rapid response!
@vlucas could you add a note in the docs about accessing the raw response, please?
It took quite a bit of digging to work out that to get the raw response (in my case a binary buffer) I needed to call Buffer.concat(res._response._raw)
@dparkerfmts
On next release, client will get raw response.
Sample code
const frisby = require('frisby');
const fs = require('fs');
it('save binary response', () => {
return frisby.setup({ request: { rawBody: true } })
.get('https://camo.githubusercontent.com/3f129b5ddde3ab0026f2d4c5460c4f15a8788bb8/68747470733a2f2f7777772e6672697362796a732e636f6d2f6173736574732f6672697362796a732e706e67')
.expect('status', 200)
.expect('header', 'Content-Type', 'image/png')
.then(res => {
let buf = Buffer.from(res.body);
return new Promise((resolve, reject) => {
fs.writeFile('res.body.png', buf, err => {
if (err) reject();
resolve();
});
});
});
});
Please wait a moment.
Accessing the raw body is now available in the latest version v2.1.0
.