Skip to content

Commit

Permalink
test(ContentTypeMiddleware): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhck authored Oct 1, 2020
1 parent f14bf3a commit f73a7fc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/middlewares/ContentTypeMiddleware.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {ContentTypeMiddleware} from "./ContentTypeMiddleware";
import {IFetchRequest} from "./FetchMiddleware";

describe("ContentTypeMiddleware", () => {
it("should add a content type application/json by default", () => {
const spy = jest.fn((options: IFetchRequest) => {
const contentType = options.headers && options.headers["content-type"];
expect(contentType).toBe("application/json");
});
const mw = new ContentTypeMiddleware();
mw.process({}, spy);
});
it("should accept a content type in constructor if we want to change it", () => {
const spy = jest.fn((options: IFetchRequest) => {
const contentType = options.headers && options.headers["content-type"];
expect(contentType).toBe("text/plain");
});
const mw = new ContentTypeMiddleware("text/plain");
mw.process({}, spy);
});
});

0 comments on commit f73a7fc

Please sign in to comment.