deno.land / x / opine@2.3.4 / test / units / app.engine.test.ts

app.engine.test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import opine from "../../mod.ts";import { describe, it } from "../utils.ts";import { expect } from "../deps.ts";import { dirname, join } from "../../deps.ts";
const __dirname = dirname(import.meta.url);
async function render(path: string, options: any) { const str = await Deno.readTextFile(path);
return str.replace("{{user.name}}", options.user.name);}
describe("app", function () { describe(".engine(ext, fn)", function () { it("should map a template engine", function (done) { const app = opine();
app.set("views", join(__dirname, "../fixtures")); app.engine(".html", render); app.locals.user = { name: "Deno" };
app.render("user.html", function (err: any, str: string) { if (err) { return done(err); }
expect(str).toEqual("<p>Deno</p>"); done(); }); });
it('should work without leading "."', function (done) { const app = opine();
app.set("views", join(__dirname, "../fixtures")); app.engine("html", render); app.locals.user = { name: "Deno" };
app.render("user.html", function (err: any, str: string) { if (err) { return done(err); }
expect(str).toEqual("<p>Deno</p>"); done(); }); });
it('should work "view engine" setting', function (done) { const app = opine();
app.set("views", join(__dirname, "../fixtures")); app.engine("html", render); app.set("view engine", "html"); app.locals.user = { name: "Deno" };
app.render("user.html", function (err: any, str: string) { if (err) { return done(err); }
expect(str).toEqual("<p>Deno</p>"); done(); }); });
it('should work "view engine" with leading "."', function (done) { const app = opine();
app.set("views", join(__dirname, "../fixtures")); app.engine(".html", render); app.set("view engine", ".html"); app.locals.user = { name: "Deno" };
app.render("user.html", function (err: any, str: string) { if (err) { return done(err); }
expect(str).toEqual("<p>Deno</p>"); done(); }); }); });});
opine

Version Info

Tagged at
2 years ago