feat($exceptionHandlerProvider): add mode `logAndRethrow` #10564

Closed
wants to merge 2 commits into
from

Projects

None yet

3 participants

@DavidSouther
Contributor

Mode logAndRethrow captures the logged exception for later inspection by test
assertions, while also throwing the exception for when the implementation
depends on thrown behavior (eg leaving the method early).

Depends on #10563
Closes #10540

@googlebot googlebot added the cla: yes label Dec 23, 2014
@DavidSouther DavidSouther fix($exceptionHandlerProvider): call `inject()` to run tests
In the current angular-mocksSpec, the tests for $exceptionHandlerProvider
call `module` to run tests on `$exceptionHandlerProvider.mode()`, but do
not call `inject()` to pump the module definitions.
50c2902
@petebacondarwin
Member

I think I agree that we should just log inside rethrow, since it won't do any harm and adding yet another config level seems unattractive and unnecessary.

@DavidSouther
Contributor

I think I agree

:) I'll redo it that way!

@DavidSouther DavidSouther feat($exceptionHandlerProvider): Log errors when rethrowing.
Current behavior draws a distinction between `log` and `rethrow` modes of
$exceptionHandler in ngMocks. This unifies the behaviors, with both modes
logging the errors while the `log` mode does not throw.

Closes #10540
98a709c
@petebacondarwin petebacondarwin commented on the diff Dec 23, 2014
src/ngMock/angular-mocks.js
* - `log`: Sometimes it is desirable to test that an error is thrown, for this case the `log`
* mode stores an array of errors in `$exceptionHandler.errors`, to allow later
* assertion of them. See {@link ngMock.$log#assertEmpty assertEmpty()} and
* {@link ngMock.$log#reset reset()}
+ * - `rethrow`: If any errors are passed to the handler in tests, it typically means that there
+ * is a bug in the application or test, so this mock will make these tests fail.
+ * For any impementations that expect exceptions to be thrown, the `rethrow` mode
@petebacondarwin
Member

@DavidSouther - thanks for this.
This looks good. I will fix the typo when merging.
The commit message needs just a tiny bit of tweaking:

  • No uppercase letter at the start of the description
  • No full stop at the end of the first line

which I will also fix when merging

@petebacondarwin petebacondarwin added a commit that referenced this pull request Dec 23, 2014
@DavidSouther @petebacondarwin DavidSouther + petebacondarwin feat(ngMock/$exceptionHandler): log errors when rethrowing
Now the `rethrow` mode will also record a log of the error in the same
way as the `log` mode.

Closes #10540
Closes #10564
2b97854
@petebacondarwin petebacondarwin added a commit that closed this pull request Dec 23, 2014
@DavidSouther @petebacondarwin DavidSouther + petebacondarwin feat(ngMock/$exceptionHandler): log errors when rethrowing
Now the `rethrow` mode will also record a log of the error in the same
way as the `log` mode.

Closes #10540
Closes #10564
deb3cb4
@petebacondarwin petebacondarwin added a commit that referenced this pull request Dec 23, 2014
@DavidSouther @petebacondarwin DavidSouther + petebacondarwin feat(ngMock/$exceptionHandler): log errors when rethrowing
Now the `rethrow` mode will also record a log of the error in the same
way as the `log` mode.

Closes #10540
Closes #10564

Conflicts:
	src/ngMock/angular-mocks.js
a4a4b82
@DavidSouther
Contributor

@petebacondarwin The branch is closed - did you want me to fix the commit message, typo, and ask for reopen?

@petebacondarwin
Member

I merged it into 1.3.x and 1.4.x already

@petebacondarwin
Member

I closed the PR by mentioning it in the commit that landed in master

@DavidSouther
Contributor

Gotcha! I see where the merge happened; I'm just so used to seeing the
purple Github "merged" icon :) Thanks for your help, and thanks for taking
this change!

On Tue Dec 23 2014 at 2:25:56 PM Pete Bacon Darwin notifications@github.com
wrote:

I closed the PR by mentioning it in the commit that landed in master


Reply to this email directly or view it on GitHub
#10564 (comment).

@petebacondarwin
Member

Yes, in Angular we don't use GitHub's merge as we rather have a linear git history.
We always rebase and do fast forward merges only (and cherry pick to other version branches).
By adding the "Closes #XXX" phrase to the bottom of the commit we can trigger Github to automatically close the PR. Perhaps we should ask them to support a "Merges #XXX" tag too?

@petems petems referenced this pull request in 24pullrequests/24pullrequests Dec 2, 2015
Closed

Getting other people's PR's in my gifts? #1017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment