Using Angular Mock Backend resource multiple times

Les_Gtec

I am trying to do backend less development in Angular while working disconnected from the backend resources.

Most functionality works fine, but if I try to use any resource a second time I get an error:

Error: Unexpected request: GET /localPTicket?ticket=123
No more request expected

The scenario I am mocking is one where, for every request to a backend service, I have to first make a Get call to get a valid Proxy Ticket, the response from this is then passed to the next API call.

I have set up a plunker that demonstrates the issue: https://plnkr.co/edit/KKa6MXcnbK1gcMiBB7MI?p=preview

I think that the issue is related to flushing the mock requests, but my understanding of the documentation is that using ngMockE2E this should not be an issue.

Thanks for any pointers!

Les

tasseKATT

It's because your are using global regexes.

Global regexes in JavaScript can be very confusing since they have a state. The first time you call it it returns the first match in the string, the second time you call it it returns the next match in the string. If there are no more matches it will return that there were no matches and reset its state.

Simply remove the g from the end of your regexes and it should behave as you expect.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mock backend for Angular / Gulp app

From Dev

Angular 5 (Karma / Jasmine Testing) - Using a mock backend to mock error responses for error messages

From Dev

Test Angular2 service with mock backend

From Dev

Angular promise multiple times

From Dev

combine multiple $resource in Angular

From Dev

How to mock an angular $resource object in Jasmine?

From Dev

Using Loop multiple times

From Dev

Using $resource with Angular

From Dev

Using $resource with Angular

From Dev

using angular $resource properly

From Dev

Using Angular $Resource what is the angular way to create a service using multiple api calls?

From Dev

Angular Controller Instantiated Multiple Times

From Java

Angular Directive call multiple times

From Dev

Angular Controller Instantiated Multiple Times

From Dev

Java Using Scanner Multiple Times

From Dev

Using QPainter with QPaintDevice multiple times

From Dev

using QNetworkAccessManager GET multiple times

From Dev

Java Using Scanner Multiple Times

From Dev

Using setData in HighCharts multiple times

From Dev

Using .trigger in a loop multiple times

From Dev

Using JavaScript script multiple times

From Dev

How to loop on a resource type multiple times in v3.8?

From Dev

Angular.js directive using stellar.js used multiple times - only the first one works

From Dev

angular2 – using same component as nested components with different inputs multiple times in single parent component

From Dev

Mock Service inside resource using jersey test framwork

From Dev

angular email validation using Regexp from backend

From Dev

php backend for uploading file using angular

From Dev

Using backend information from response: Angular

From Dev

Angular ui - tabs controllers executed multiple times

Related Related

  1. 1

    Mock backend for Angular / Gulp app

  2. 2

    Angular 5 (Karma / Jasmine Testing) - Using a mock backend to mock error responses for error messages

  3. 3

    Test Angular2 service with mock backend

  4. 4

    Angular promise multiple times

  5. 5

    combine multiple $resource in Angular

  6. 6

    How to mock an angular $resource object in Jasmine?

  7. 7

    Using Loop multiple times

  8. 8

    Using $resource with Angular

  9. 9

    Using $resource with Angular

  10. 10

    using angular $resource properly

  11. 11

    Using Angular $Resource what is the angular way to create a service using multiple api calls?

  12. 12

    Angular Controller Instantiated Multiple Times

  13. 13

    Angular Directive call multiple times

  14. 14

    Angular Controller Instantiated Multiple Times

  15. 15

    Java Using Scanner Multiple Times

  16. 16

    Using QPainter with QPaintDevice multiple times

  17. 17

    using QNetworkAccessManager GET multiple times

  18. 18

    Java Using Scanner Multiple Times

  19. 19

    Using setData in HighCharts multiple times

  20. 20

    Using .trigger in a loop multiple times

  21. 21

    Using JavaScript script multiple times

  22. 22

    How to loop on a resource type multiple times in v3.8?

  23. 23

    Angular.js directive using stellar.js used multiple times - only the first one works

  24. 24

    angular2 – using same component as nested components with different inputs multiple times in single parent component

  25. 25

    Mock Service inside resource using jersey test framwork

  26. 26

    angular email validation using Regexp from backend

  27. 27

    php backend for uploading file using angular

  28. 28

    Using backend information from response: Angular

  29. 29

    Angular ui - tabs controllers executed multiple times

HotTag

Archive