Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(ngMocks): add expectRoute and whenRoute shortcuts with colon param matching #12406

Closed
wants to merge 1 commit into from
Closed

feat(ngMocks): add expectRoute and whenRoute shortcuts with colon param matching #12406

wants to merge 1 commit into from

Conversation

dmaloneycalu
Copy link

Adds a whenRoute() and expectRoute() function to $httpBackend service to make mocking out responses similar to writing API routes on a server. Also includes colon delimited param matching so that expect and when handlers can match requests in the form of /user/:id, identical to the way ngRoute matches urls in an Angular application.

Here's an example file that reflects one of the use cases for the feature (paged API responses).

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.

@googlebot
Copy link

CLAs look good, thanks!

@dmaloneycalu
Copy link
Author

CLA signed and builds passing. Any feedback here?

@dmaloneycalu
Copy link
Author

Any thoughts or suggestions on this? Potentially a 1.4.x or 1.5 addition?

@vojtajina @petebacondarwin @matsko

@dmaloneycalu
Copy link
Author

Have not seen much action on the Angular repo lately, accidentally closed the PR (was going to comment, thought was just closing the comment, sorry!), reopened.

@dmaloneycalu
Copy link
Author

I can rebase this on master and squash the commits if necessary. Still haven't received any feedback. @angular

@petebacondarwin
Copy link
Contributor

I like the look of this @dmaloneycalu please do rebase. We probably won't be able to get to it until after AngularConnect now.

@gkalpak
Copy link
Member

gkalpak commented Oct 2, 2015

The tests might also make good use of the they() helper.

@gkalpak
Copy link
Member

gkalpak commented Oct 2, 2015

BTW, the real benefit I see in this change comes from the added keys parameter. (Matching routes could be achieved with RegExps before.)

So, we need docs and tests for that :)

@dmaloneycalu
Copy link
Author

@petebacondarwin can do.

@gkalpak I'll add additional tests for the parameter addition and rewrite some of the tests to take advantage of the they() helper

@dmaloneycalu
Copy link
Author

@petebacondarwin @gkalpak

  • squashed commits
  • added additional tests for params matching outside of whenRoute and expectRoute
  • fixed a few documentation lines I was missing

@@ -1251,20 +1251,21 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
* data string and returns true if the data is as expected.
* @param {(Object|function(Object))=} headers HTTP headers or function that receives http header
* object and returns true if the headers match the current definition.
* @param {(Array)=} keys Array of keys to assign to regex matches in the respond params for the url.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this needs a bit more explanation for people coming to this documentation without looking at the code. Perhaps we could have a single section in the ngMock.$httpBackend description that explains what can now be done with regexes and keys then simply refer each fo these parameter descriptions to that section?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a stab at this and notify you when I've pushed it.

…am matching

Add whenRoute method to $httpBackend to support matching similar to API backends, which
handles responses based on the query to a particular route. Also includes params in the respond
function to give access to both query params and route colon delimited values.

This is a feature request and is not associated with any open issue
@dmaloneycalu
Copy link
Author

@petebacondarwin

  • Added a section to the documentation
  • Reordered code so documentation for whenRoute and expectRoute were at bottom of shortcuts list
  • Pointed method param declarations to see above for further explanation

I'm not an English professor, so feel free to let me know if anything isn't well defined enough

@petebacondarwin
Copy link
Contributor

Thanks @dmaloneycalu I will take a look

});
```
*
* By default, query parameters on requested urls are parsed onto the params object, so a requsted url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requsted --> requested

@petebacondarwin
Copy link
Contributor

I did a bunch of tidy up on the docs and landed. Thanks @dmaloneycalu
@gkalpak I missed that indentation. Sorry.

petebacondarwin added a commit that referenced this pull request Oct 8, 2015
@dmaloneycalu
Copy link
Author

Sorry on the indentation, was trying to be thorough checking since my editor is usually 4 spaces for indentation. Glad I could contribute.

@dmaloneycalu dmaloneycalu deleted the feat-ngMocks-whenRoute-respond-params branch October 8, 2015 15:13
@gkalpak
Copy link
Member

gkalpak commented Oct 8, 2015

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants