1 | var request = require('supertest');
|
2 | var assert = require('assert');
|
3 | var hbs = require('..');
|
4 |
|
5 | describe('express-hbs', function() {
|
6 |
|
7 | describe('defaults', function() {
|
8 | var app;
|
9 |
|
10 | beforeEach(function() {
|
11 | var example = require('../example/app');
|
12 | app = example.create(hbs.create());
|
13 | });
|
14 |
|
15 |
|
16 | it('should render using default layout', function(done) {
|
17 | request(app)
|
18 | .get('/')
|
19 | .expect(/DEFAULT LAYOUT/, done);
|
20 | });
|
21 |
|
22 | it('should render layout declared in markup', function(done) {
|
23 | request(app)
|
24 | .get('/fruits')
|
25 | .expect(/DECLARATIVE LAYOUT/, done);
|
26 | });
|
27 |
|
28 | it('should render nested declarative layouts correctly', function(done) {
|
29 | request(app)
|
30 | .get('/fruits/apple')
|
31 | .expect(/DECLARATIVE LAYOUT/)
|
32 | .expect(/NESTED LAYOUT/, done);
|
33 | });
|
34 |
|
35 | it('should render layout specified as locals', function(done) {
|
36 | request(app)
|
37 | .get('/veggies')
|
38 | .expect(/PROGRAMMATIC LAYOUT/, done);
|
39 | });
|
40 |
|
41 | it('should render nested layouts correctly when first layout is specified as locals', function(done) {
|
42 | request(app)
|
43 | .get('/veggies/carrot')
|
44 | .expect(/PROGRAMMATIC LAYOUT/)
|
45 | .expect(/NESTED LAYOUT/, done);
|
46 | });
|
47 |
|
48 | it('should render partial', function(done) {
|
49 | request(app)
|
50 | .get('/veggies')
|
51 | .expect(/jquery\.js/)
|
52 | .expect(/Other partial/, done);
|
53 | });
|
54 |
|
55 | it('should render sub partial', function(done) {
|
56 | request(app)
|
57 | .get('/veggies')
|
58 | .expect(/just a comment/, done);
|
59 | });
|
60 |
|
61 | it('should render block', function(done) {
|
62 | request(app)
|
63 | .get('/')
|
64 | .expect(/color: blue/, done);
|
65 | });
|
66 |
|
67 | it('should render block default content', function(done) {
|
68 | request(app)
|
69 | .get('/')
|
70 | .expect(/Default block content/, done);
|
71 | });
|
72 |
|
73 | it('should render block content instead of default content when contentFor is declared', function(done) {
|
74 | request(app)
|
75 | .get('/replace')
|
76 | .expect(/Non-default block content/, done);
|
77 | });
|
78 |
|
79 | it('should replace {{body}}', function(done) {
|
80 | request(app)
|
81 | .get('/')
|
82 | .expect(/Vegetables/, done);
|
83 | });
|
84 |
|
85 | });
|
86 |
|
87 | describe('instances', function() {
|
88 | it('should create isolated instances', function() {
|
89 | var hbs2 = hbs.create();
|
90 | var hbs3 = hbs.create();
|
91 |
|
92 | assert(hbs !== hbs2 && hbs !== hbs3 && hbs2 !== hbs3);
|
93 | });
|
94 | });
|
95 | });
|