I want to unit test my function which basically builds an array of observables from an array of parameters (TypeScript code):
private BuildObservables(parameters: Parameter[]) {
var observables = {};
for (var parameterName in parameters) {
var p = parameters[parameterName];
// Build observable
observables[parameterName] = ko.observable(p.Value);
// Attach validation
if (p.IsRequired) {
observables[parameterName].extend({ required: true });
}
}
return observables;
}
My test look like this:
var parameters = [];
// new Parameter(int value, bool isRequired)
parameters["Param1"] = new Parameter("123", true);
parameters["Param2"] = new Parameter("456", false);
var viewModel = BuildObservables(parameters);
ok(viewModel["Param1"] != null);
ok(viewModel["Param2"] != null);
In case of the first parameter where isRequired
was set to true
, how to check if extension (validation) was applied ("Attach validation" part in BuildObservables)?
Edit:
In the other function I'm attaching subscribers and I don't know how to test if they were correctly attached.