Pregunta

I am trying to play around with $q, write some tests, try to stub promises etc. and I wondered if there is a way to return fully resolved promise like one can do it with whenjs, when("stuff to return), something that would be equal to this

  function fullyResolvedPromise(expectedResponse) {

        var dfd = $q.defer();
        dfd.resolve(expectedResponse);
        $rootScope.$apply();

        return dfd.promise;
    }

Clarification: I know this code works, but I want to do it without writing this function. I want to do something like this $q(expectedresponse) and get equivalent to above code. That is what I am after. Just like with whenjs you can write when(stuffToResolve) and it would return you a fully resolved promise.

¿Fue útil?

Solución

After posting a clarification I re-read the documentation and there it is - when() method. So I can use $q.when(stuffToResolve) and it would be equal to calling the above function.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top