Skip to content

Commit 9fa313c

Browse files
author
cloudhead
committed
Fix incorrect binding in test functions.
`env` wasn't being closed over properly.
1 parent b10a30a commit 9fa313c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/vows.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,11 @@ function addVows(tests) {
331331
// before calling the inner context. Else, just run the inner context
332332
// synchronously.
333333
if (topic) {
334-
topic.addListener("success", function (vow, ctx) {
334+
topic.addListener("success", function (vow, ctx, env) {
335335
return function (val) {
336336
return run(new(Context)(vow, ctx, env), lastTopic);
337337
};
338-
}(vow, ctx));
338+
}(vow, ctx, env));
339339
} else {
340340
run(new(Context)(vow, ctx, env), lastTopic);
341341
}

test/vows-test.js

+20
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,26 @@ vows.describe("Vows").addVows({
237237
}
238238
}
239239
}
240+
}).addVows({
241+
"Sibling contexts": {
242+
"'A', with `this.foo = true`": {
243+
topic: function () {
244+
this.foo = true;
245+
return this.foo;
246+
},
247+
"should have `this.foo` set to true": function (res) {
248+
assert.equal(res, true);
249+
}
250+
},
251+
"'B', with nothing set": {
252+
topic: function () {
253+
return this.foo;
254+
},
255+
"should have `this.foo` be undefined": function (res) {
256+
assert.isUndefined(res);
257+
}
258+
}
259+
}
240260
}).addVows({
241261
"A 2nd test suite": {
242262
topic: function () {

0 commit comments

Comments
 (0)