I need to verify if the passed variable is being modified within a function parameter. It's important that the variable itself undergoes a change.
For my unit tests, I am utilizing Karma and Jasmine.
In my Controller code snippet:
angular.module('myApp').controller('MyController', function($scope){
$scope.functions = {};
$scope.functions.deleteSomething = function(someObject, condition){
someObject.someArray = someObject.someArray.filter(function(existingCondition){
return existingCondition !== condition;
});
};
})
My Unit Test case:
describe('myControllerSpec', function(){
var scope, controller;
beforeEach(module('myApp'));
beforeEach(inject(function($injector, $controller){
scope = $injector.get('$rootScope').$new();
controller = $controller('MyController', {
$scope: scope
});
}));
it("should validate if the provided variable gets altered or not", function(){
object = {
someArray: [
{
temp: 'dummy1'
},
{
temp: 'dummy2'
}
]
};
condition = {
temp: 'dummy1'
}
scope.functions.deleteSomething(object, condition);
expect(object.someArray).toEqual([
{
temp: 'dummy2'
}
]);
});
})
I'm facing challenges in understanding why the variable doesn't reflect any changes. Could this be due to its lack of attachment to scope?
However, I prefer not to link it to scope for testing purposes. Modifying the Controller isn't an option as someone else manages it.
Does anyone have any recommendations on how I can effectively test this piece of code?