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

feat($exceptionHandlerProvider): add mode logAndRethrow #10564

Closed
wants to merge 2 commits into from
Closed

feat($exceptionHandlerProvider): add mode logAndRethrow #10564

wants to merge 2 commits into from

Conversation

DavidSouther
Copy link
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

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.
@petebacondarwin
Copy link
Contributor

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
Copy link
Contributor Author

I think I agree

:) I'll redo it that way!

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
* - `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
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

@petebacondarwin
Copy link
Contributor

@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 pushed a commit that referenced this pull request Dec 23, 2014
Now the `rethrow` mode will also record a log of the error in the same
way as the `log` mode.

Closes #10540
Closes #10564
petebacondarwin pushed a commit that referenced this pull request Dec 23, 2014
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
@DavidSouther
Copy link
Contributor Author

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

@petebacondarwin
Copy link
Contributor

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

@petebacondarwin
Copy link
Contributor

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

@DavidSouther
Copy link
Contributor Author

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
Copy link
Contributor

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?

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

Successfully merging this pull request may close these issues.

angular.mock.$ExceptionHandlerProvider Provide mode logAndRethrow
3 participants