I have the First case when product id should be undefined.
var $stateParamsStub = {
productId: undefined
}
In my controller, I am checking for isUpdate true or false. If productId is undefined it means isUpdate should be false in another case it should be true
$scope.isUpdate = stateParams.scheduleId ? true : false;
My Test File
$injector.invoke(myController, this, {
$scope: $scope,
$stateParams: $stateParamsStub
});
My first test case, which is working as expected because I set stateParams.scheduleId to undefined while injecting
it('should check update as false', function () {
expect($scope.isUpdate).toBeFalsy();
});
My case 2, which is failing
it('should check update as false', function () {
$stateParamsStub = {
productId: "86C07C05-41FB-41E9"
}
$scope.$digest();
expect($scope.isUpdate).toBeTruthy();
});
The output of the second case: Expected false to be truthy.
I know before every "it" before each gets executed where It is setting the default value which I assigned earlier. How to change that value for another test ? so it takes an updated value?
Aucun commentaire:
Enregistrer un commentaire