deno.land / x / opine@2.3.4 / test / units / req.is.test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166import { opine } from "../../mod.ts";import { superdeno } from "../deps.ts";import { describe, it } from "../utils.ts";
describe("req.is()", function () { describe("when given a mime type", function () { it("should return the type when matching", function (done) { const app = opine();
app.use(function (req, res) { res.json(req.is("application/json")); });
superdeno(app) .post("/") .type("application/json") .send("{}") .expect(200, '"application/json"', done); });
it("should return false when not matching", function (done) { const app = opine();
app.use(function (req, res) { res.json(req.is("image/jpeg")); });
superdeno(app) .post("/") .type("application/json") .send("{}") .expect(200, "false", done); });
it("should ignore charset", function (done) { const app = opine();
app.use(function (req, res) { res.json(req.is("application/json")); });
superdeno(app) .post("/") .type("application/json; charset=UTF-8") .send("{}") .expect(200, '"application/json"', done); }); });
describe("when content-type is not present", function () { it("should return false", function (done) { const app = opine();
app.use(function (req, res) { res.json(req.is("application/json")); });
superdeno(app).post("/").send("{}").expect(200, "false", done); }); });
describe("when given an extension", function () { it("should lookup the mime type", function (done) { const app = opine();
app.use(function (req, res) { res.json(req.is("json")); });
superdeno(app) .post("/") .type("application/json") .send("{}") .expect(200, '"json"', done); }); });
describe("when given */subtype", function () { it("should return the full type when matching", function (done) { const app = opine();
app.use(function (req, res) { res.json(req.is("*/json")); });
superdeno(app) .post("/") .type("application/json") .send("{}") .expect(200, '"application/json"', done); });
it("should return false when not matching", function (done) { const app = opine();
app.use(function (req, res) { res.json(req.is("*/html")); });
superdeno(app) .post("/") .type("application/json") .send("{}") .expect(200, "false", done); });
it("should ignore charset", function (done) { const app = opine();
app.use(function (req, res) { res.json(req.is("*/json")); });
superdeno(app) .post("/") .type("application/json; charset=UTF-8") .send("{}") .expect(200, '"application/json"', done); }); });
describe("when given type/*", function () { it("should return the full type when matching", function (done) { const app = opine();
app.use(function (req, res) { res.json(req.is("application/*")); });
superdeno(app) .post("/") .type("application/json") .send("{}") .expect(200, '"application/json"', done); });
it("should return false when not matching", function (done) { const app = opine();
app.use(function (req, res) { res.json(req.is("text/*")); });
superdeno(app) .post("/") .type("application/json") .send("{}") .expect(200, "false", done); });
it("should ignore charset", function (done) { const app = opine();
app.use(function (req, res) { res.json(req.is("application/*")); });
superdeno(app) .post("/") .type("application/json; charset=UTF-8") .send("{}") .expect(200, '"application/json"', done); }); });});
Version Info