0

I am trying to test rest service like "/service/home/autolaunch?rnd=" The query parameter "rnd" value always is unique to get rid of internet explorer caching issue. While writing jasmine test case for above back end service- I got error 'Unexpected request' as query parameter is different for each time. is there any way to skip query parameter while writing jasmine test.

In service the call is like that-

http.get('/service/home/autolaunch', {params:{rnd:new Date().getTime()}}).then(
          function(data){
          // TO do
});

The Jasmine test case is-

httpBackend.when('GET','/service/home/autolaunch').respond(-- to do);

even if define test case in following way-

httpBackend.when('GET','/service/home/autolaunch?rnd=' + new Date().getTime()).respond(-- to do);

still getting Unexpected request.

After doing debugging got to know the time stamp value is different.

1 Answer 1

2

You can use a regular expression in the $httpBackend.expectGet() method:

var regex = new RegExp('/service/home/autolaunch\\?rnd=.*');
httpBackend.expectGET(regex).respond(...);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Dennis. Successfully able to execute tests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.