UNPKG

2.08 kBJavaScriptView Raw
1// Test format: https://mochajs.org/#bdd
2// Assertion format: http://chaijs.com/api/bdd/
3
4let expect = require('chai').expect,
5 jsdom = require("jsdom"),
6 distill = require("../dist/template.js");
7
8describe("Distill", function() {
9 describe("render", function() {
10 it("Should have a render function.", function() {
11 expect(distill.render).to.be.an.instanceof(Function);
12 });
13 });
14 //
15 // html
16 //
17 describe("html", function() {
18 it("Should have a html function.", function() {
19 expect(distill.html).to.be.an.instanceof(Function);
20 });
21 it("Should add a language attribute to html element, if not present.", function() {
22 var doc = jsdom.jsdom("");
23 let before = jsdom.serializeDocument(doc);
24 distill.html(doc, {});
25 let after = jsdom.serializeDocument(doc);
26 expect(after).to.match(new RegExp('<html lang="en">'));
27 });
28 it("Should not add a language attribute to html element, if already present.", function() {
29 var doc = jsdom.jsdom('<html lang="ab">');
30 let before = jsdom.serializeDocument(doc);
31 distill.html(doc, {});
32 let after = jsdom.serializeDocument(doc);
33 expect(after).to.not.match(new RegExp('lang="en"'));
34 });
35 it("Should add a meta charset tag, if not present.", function() {
36 var doc = jsdom.jsdom("");
37 let before = jsdom.serializeDocument(doc);
38 distill.html(doc, {});
39 let after = jsdom.serializeDocument(doc);
40 expect(after).to.match(new RegExp('<meta charset="utf-8">'));
41 });
42 it("Should add a meta viewport tag, if not present.", function() {
43 var doc = jsdom.jsdom("");
44 let before = jsdom.serializeDocument(doc);
45 distill.html(doc, {});
46 let after = jsdom.serializeDocument(doc);
47 expect(after).to.match(new RegExp('<meta name="viewport" content="width=device-width, initial-scale=1">'));
48 });
49 });
50
51 //
52 // styles
53 //
54 describe("styles", function() {
55 it("Should have a styles function.", function() {
56 expect(distill.styles).to.be.an.instanceof(Function);
57 });
58 })
59});