โ ๏ธ Not yet ready for production. Many things are subject to change.
Superfetch is a high-level abstraction for testing APIs.
Assert status code is equal 200
import { Fetch } from "./deps.ts";
const response = Fetch.get("http://example.com")
.end();
response.expect(200); // assert status code is 200
Assert Content-Type is equal "application/json"
import { Fetch } from "./deps.ts";
const response = await Fetch.get("http://example.com")
.end();
response.expect("Content-Type", "application/json"); // assert header
You can also use regular expressions
import { Fetch } from "./deps.ts";
const response = await Fetch.get("http://example.com")
.end();
response.expect("Content-Type", /json/); // assert header
Content-Type is set based on body type.
import { Fetch } from "./deps.ts";
const response = await Fetch.post("http://example.com")
.send({ foo: "bar" }); // Content-Type will be set to application/json
import { Fetch } from "./deps.ts";
const response = await Fetch.post("http://example.com")
.send("Hello There!"); // Content-Type will be set to text/plain
Checks if status code is equal to given status code.
Checks if header is equal to given value.
Checks if header matches regular expression.
Sends request with body and returns FetchResponse object.
Send request and returns FetchResponse object.
import { Fetch } from "./deps.ts";
const response = await Fetch.post("http://example.com")
.set("Content-Type", "application/json")
.set("Authorization", "Bearer 12345")
.send({ foo: "bar" });
response
.expect(200)
.expect("Content-Type", "application/json")
.expect("Authorization", /Bearer/);
const body = await response.json();
assertEquals(body, { foo: "bar" });