Skip to content

Commit 9681a3b

Browse files
alistairjcbrownTheLarkInn
authored andcommitted
Add tests for HotUpdateChunkTemplate (webpack#3867)
1 parent 0542f4a commit 9681a3b

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
var should = require("should");
2+
var sinon = require("sinon");
3+
var HotUpdateChunkTemplate = require("../lib/HotUpdateChunkTemplate");
4+
5+
describe("HotUpdateChunkTemplate", function() {
6+
var env;
7+
8+
beforeEach(function() {
9+
env = {
10+
myHotUpdateChunkTemplate: new HotUpdateChunkTemplate({})
11+
};
12+
});
13+
14+
describe("render", function() {
15+
beforeEach(function() {
16+
env.renderContext = {
17+
renderChunkModules: sinon.spy(),
18+
applyPluginsWaterfall: sinon.spy()
19+
};
20+
var renderArguments = [
21+
"id", ["module1", "module2"],
22+
["module3", "module4"],
23+
{},
24+
"moduleTemplate", ["template1"]
25+
];
26+
env.myHotUpdateChunkTemplate.render.apply(env.renderContext, renderArguments);
27+
env.pluginsCall = env.renderContext.applyPluginsWaterfall;
28+
});
29+
30+
it("renders chunk modules", function() {
31+
env.renderContext.renderChunkModules.callCount.should.be.exactly(1);
32+
});
33+
34+
it("applies modules plugins", function() {
35+
env.pluginsCall.callCount.should.be.exactly(2);
36+
env.pluginsCall.firstCall.args[0].should.be.exactly("modules");
37+
});
38+
39+
it("applies render plugins", function() {
40+
env.pluginsCall.callCount.should.be.exactly(2);
41+
env.pluginsCall.secondCall.args[0].should.be.exactly("render");
42+
});
43+
});
44+
45+
describe("updateHash", function() {
46+
beforeEach(function() {
47+
env.hash = {
48+
update: sinon.spy()
49+
};
50+
env.updateHashContext = {
51+
applyPlugins: sinon.spy()
52+
};
53+
env.myHotUpdateChunkTemplate.updateHash.call(env.updateHashContext, env.hash);
54+
});
55+
56+
it("updates hash", function() {
57+
env.hash.update.callCount.should.be.exactly(2);
58+
env.hash.update.firstCall.args[0].should.be.exactly("HotUpdateChunkTemplate");
59+
env.hash.update.secondCall.args[0].should.be.exactly("1");
60+
});
61+
62+
it("applies hash plugin", function() {
63+
env.updateHashContext.applyPlugins.callCount.should.be.exactly(1);
64+
env.updateHashContext.applyPlugins.firstCall.args[0].should.be.exactly("hash");
65+
env.updateHashContext.applyPlugins.firstCall.args[1].should.be.exactly(env.hash);
66+
});
67+
});
68+
});

0 commit comments

Comments
 (0)