Skip to content

Commit fff5744

Browse files
committed
Add tests
1 parent ef3aeac commit fff5744

File tree

4 files changed

+128
-15
lines changed

4 files changed

+128
-15
lines changed

test/techs/bh-client-module.test.js

+37-15
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,45 @@ describe('bh-client-module', function () {
5252
return runTest(test, options);
5353
});
5454

55-
it('mimic', function () {
56-
var test = [
57-
'chai.should();',
58-
'describe("bh-client-module", function () {',
59-
'it("autogenerated test", function (done) {',
60-
'modules.require("BEMHTML", function (BEMHTML) {',
61-
'BEMHTML.apply({ block: "block" }).should.equal(\'<a class="block"></a>\');',
62-
'done();',
55+
describe('mimic', function () {
56+
it('mimic as a string', function () {
57+
var test = [
58+
'chai.should();',
59+
'describe("bh-client-module", function () {',
60+
'it("autogenerated test", function (done) {',
61+
'modules.require("BEMHTML", function (BEMHTML) {',
62+
'BEMHTML.apply({ block: "block" }).should.equal(\'<a class="block"></a>\');',
63+
'done();',
64+
'});',
6365
'});',
64-
'});',
65-
'});'
66-
].join('\n'),
67-
options = {
68-
mimic: 'BEMHTML'
69-
};
66+
'});'
67+
].join('\n'),
68+
options = {
69+
mimic: 'BEMHTML'
70+
};
71+
72+
return runTest(test, options);
73+
});
7074

71-
return runTest(test, options);
75+
it('mimic to different template engines', function () {
76+
var test = [
77+
'chai.should();',
78+
'describe("bh-client-module", function () {',
79+
'it("autogenerated test", function (done) {',
80+
'modules.require(["BEMHTML", "render"], function (BEMHTML, render) {',
81+
'BEMHTML.apply({ block: "block" }).should.equal(\'<a class="block"></a>\');',
82+
'render.apply({ block: "block" }).should.equal(\'<a class="block"></a>\');',
83+
'done();',
84+
'});',
85+
'});',
86+
'});'
87+
].join('\n'),
88+
options = {
89+
mimic: ['BEMHTML', 'render']
90+
};
91+
92+
return runTest(test, options);
93+
});
7294
});
7395

7496
describe('jsAttr', function () {

test/techs/bh-client.test.js

+35
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,41 @@ describe('bh-client', function () {
6767
return runTest(test, options);
6868
});
6969

70+
describe('mimic', function () {
71+
it('mimic as a string', function () {
72+
var test = [
73+
'chai.should();',
74+
'describe("bh-client", function () {',
75+
'it("autogenerated test", function () {',
76+
'BEMHTML.apply({ block: "block" }).should.equal(\'<a class="block"></a>\');',
77+
'})',
78+
'})'
79+
].join('\n'),
80+
options = {
81+
mimic: 'BEMHTML'
82+
};
83+
84+
return runTest(test, options);
85+
});
86+
87+
it('mimic to different template engines', function () {
88+
var test = [
89+
'chai.should();',
90+
'describe("bh-client", function () {',
91+
'it("autogenerated test", function () {',
92+
'BEMHTML.apply({ block: "block" }).should.equal(\'<a class="block"></a>\');',
93+
'render.apply({ block: "block" }).should.equal(\'<a class="block"></a>\');',
94+
'})',
95+
'})'
96+
].join('\n'),
97+
options = {
98+
mimic: ['BEMHTML', 'render']
99+
};
100+
101+
return runTest(test, options);
102+
});
103+
});
104+
70105
describe('jsAttr', function () {
71106
it('should use dafault jsAttrName and jsAttrScheme params', function () {
72107
var test = generateTest(

test/techs/bh-server-include.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ describe('bh-server-include', function () {
8181
return assert(bemjson, html, templates);
8282
});
8383

84+
describe('mimic', function () {
85+
it('mimic to BEMHTML', function () {
86+
var templates = [
87+
'bh.match("block", function(ctx) {ctx.tag("a");});'
88+
],
89+
bemjson = { block: 'block' },
90+
html = '<a class="block"></a>',
91+
options = { mimic: 'BEMHTML' };
92+
93+
return assert(bemjson, html, templates, options);
94+
});
95+
96+
it('mimic as an array', function () {
97+
var templates = [
98+
'bh.match("block", function(ctx) {ctx.tag("a");});'
99+
],
100+
bemjson = { block: 'block' },
101+
html = '<a class="block"></a>',
102+
options = { mimic: ['BH', 'BEMHTML'] };
103+
104+
return assert(bemjson, html, templates, options);
105+
});
106+
});
107+
84108
describe('caches', function () {
85109
it('must use cached bhFile', function () {
86110
var scheme = {
@@ -254,5 +278,9 @@ function assert(bemjson, html, templates, options) {
254278
return bundle.runTechAndRequire(bhServerInclude, options)
255279
.spread(function (bh) {
256280
bh.apply(bemjson).must.be(html);
281+
282+
options && options.mimic && [].concat(options.mimic).forEach(function (name) {
283+
bh[name].apply(bemjson).must.be(html);
284+
});
257285
});
258286
}

test/techs/bh-server.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,30 @@ describe('bh-server', function () {
115115
});
116116
});
117117

118+
describe('mimic', function () {
119+
it('mimic to BEMHTML', function () {
120+
var templates = [
121+
'bh.match("block", function(ctx) {ctx.tag("a");});'
122+
],
123+
bemjson = { block: 'block' },
124+
html = '<a class="block"></a>',
125+
options = { mimic: 'BEMHTML' };
126+
127+
return assert(bemjson, html, templates, options);
128+
});
129+
130+
it('mimic as an array', function () {
131+
var templates = [
132+
'bh.match("block", function(ctx) {ctx.tag("a");});'
133+
],
134+
bemjson = { block: 'block' },
135+
html = '<a class="block"></a>',
136+
options = { mimic: ['BH', 'BEMHTML'] };
137+
138+
return assert(bemjson, html, templates, options);
139+
});
140+
});
141+
118142
describe('caches', function () {
119143
it('must use cached bhFile', function () {
120144
var scheme = {
@@ -263,5 +287,9 @@ function assert(bemjson, html, templates, options) {
263287
return bundle.runTechAndRequire(bhServer, options)
264288
.spread(function (bh) {
265289
bh.apply(bemjson).must.be(html);
290+
291+
options && options.mimic && [].concat(options.mimic).forEach(function (name) {
292+
bh[name].apply(bemjson).must.be(html);
293+
});
266294
});
267295
}

0 commit comments

Comments
 (0)