-1

How to cover the highlighted code

genericFunctionsService.getConfigDetails().then((config) => {

        let navigationURL = genericFunctionsService.replacePlaceHolders(config.data.navigationUrl, {
            '{edition}': editionObject.editionCode,
            '{language}': editionObject.editionLanguage
        });
         *this.getNavigationItemsFromService(navigationURL).then(( navigationData ) => {
            let tempNavItem = this.filterNavigationItems(navigationData.data, editionObject);
            deferred.resolve(tempNavItem);
        }).catch(function(error) {
            deferred.reject(error);
        });*
    });
    return deferred.promise;
}

this.getNavigationItemsFromService(navigationURL)
  .then(( navigationData ) => {
    let tempNavItem = this.filterNavigationItems(navigationData.data, editionObject);
    deferred.resolve(tempNavItem); 
}).catch(function(error) {
    deferred.reject(error); 
}); 

After dot then it is showing me orange color which is not covered, i am not able to cover this with my unit testing

Jeff Dean
  • 157
  • 1
  • 1
  • 10
  • *this.getNavigationItemsFromService(navigationURL).then(( navigationData ) => { let tempNavItem = this.filterNavigationItems(navigationData.data, editionObject); deferred.resolve(tempNavItem); }).catch(function(error) { deferred.reject(error); });* After then it is showing me orange color which is covered, i am not able to cover this with my unit testing – Jeff Dean Nov 02 '18 at 13:29
  • Avoid using a [deferred anti-pattern](https://stackoverflow.com/questions/30750207/is-this-a-deferred-antipattern). – georgeawg Nov 02 '18 at 13:43
  • @georgeawg Yes, but in my case, how to change deferred anti Pattern, because I need tempNavItem from navigationData.data, plz help – Jeff Dean Nov 02 '18 at 14:00

1 Answers1

0

how to change deferred anti Pattern, because I need tempNavItem from navigationData.data, plz help

genericFunctionsService.getConfigDetails()
  .then((config) => {  
    let navigationURL = genericFunctionsService.replacePlaceHolders(config.data.navigationUrl, {
        '{edition}': editionObject.editionCode,
        '{language}': editionObject.editionLanguage
    });
    var promise = this.getNavigationItemsFromService(navigationURL)
      .then(( navigationData ) => {
        let tempNavItem = this.filterNavigationItems(navigationData.data, editionObject);
        return tempNavItem;
    }).catch(function(error) {
        console.log(error);
        throw error;
    });
    return promise;
});

The .then method returns a new promise which is resolved or rejected via the return value of the successCallback, errorCallback (unless that value is a promise, in which case it is resolved with the value which is resolved in that promise using promise chaining).

For more information, see AngularJS $q Service API Reference - The Promise API.

georgeawg
  • 48,608
  • 13
  • 72
  • 95