Code Monkey home page Code Monkey logo

superfetch's Introduction

Superfetch

โš ๏ธ Not yet ready for production. Many things are subject to change.

About

Superfetch is a high-level abstraction for testing APIs.

Examples

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

API

.expect(statusCode: number): Fetch

Checks if status code is equal to given status code.

.expect(k: string, v: string): Fetch

Checks if header is equal to given value.

.expect(k: string, regex: RegExp): Fetch

Checks if header matches regular expression.

.send(body: any): FetchResponse

Sends request with body and returns FetchResponse object.

.end(): FetchResponse

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" });

superfetch's People

Contributors

unpin avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.