Commit 759a3c4f by Peter Fogg

Fix `withData` and `withConfiguration` helpers.

Both of them dynamically generate specs which close over the iteration
variable of a for loop. Closures capture *references*, not values, and
so when the variable is mutated on loop iteration its new value is
used when the spec is called. This means that instead of running a
spec with n different values, we run the spec n times with the same
value. This is bad.
parent cdd5a6f8
......@@ -13,9 +13,11 @@ define([], function () {
var withData = function (data, func) {
for (var name in data) {
if (data.hasOwnProperty(name)) {
it(name, function () {
func.apply(this, data[name]);
});
(function (name) {
it(name, function () {
func.apply(this, data[name]);
});
})(name);
}
}
};
......@@ -31,12 +33,14 @@ define([], function () {
var withConfiguration = function (config, setup, test) {
for (var name in config) {
if (config.hasOwnProperty(name)) {
describe(name, function () {
beforeEach(function () {
setup.apply(this, config[name]);
(function (name) {
describe(name, function () {
beforeEach(function () {
setup.apply(this, config[name]);
});
test();
});
test();
});
})(name);
}
}
};
......
......@@ -171,10 +171,11 @@ define([
]
}, function (url, expectedEvent) {
var teamsTabView = createTeamsTabView(this, {
userInfo: TeamSpecHelpers.createMockUserInfo({staff: true})
});
userInfo: TeamSpecHelpers.createMockUserInfo({staff: true})
});
teamsTabView.teamsCollection = TeamSpecHelpers.createMockTeams();
teamsTabView.router.navigate(url, {trigger: true});
if (AjaxHelpers.currentRequest(requests)) {
if (requests.length > requests.currentIndex) {
AjaxHelpers.respondWithJson(requests, {});
}
expect(Logger.log).toHaveBeenCalledWith('edx.team.page_viewed', expectedEvent);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment