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

feat(ngMock): add sharedInjector() to angular.mock.module #14093

Closed

Conversation

timruffles
Copy link
Contributor

Allows users to opt-in to using a shared injector within a describe() context, via angular.mock.module.sharedInjector().

This enables Jasmine 2.x/mocha's beforeAll()/before() hooks to be used with Angular, fixing issue #10238 as previously discussed.

Beyond the tests added to angular-mocksSpec.js, I've also created JSFiddles with the new behaviour working alongside:

  • Jasmine 2.x
  • Mocha
  • Jasmine 1.x (to simply demonstrate it doesn't break anything - 1.x doesn't have beforeAll so can't use sharedInjector)

The verification tests above contain tests suggested by @lgalfaso. cc/@petebacondarwin. The unit tests added contain a little test framework stub, as it was nigh on impossible to test this feature without interference from the rest of the Angular test machinery. Testing inception!

@petebacondarwin
Copy link
Member

I'll review this later this week. Thanks

* ## Example
*
* Typically beforeAll is used to make many assertions about a single operation. This can
* cut down test run-tims, and produce focussed tests with a single assertion.
Copy link
Member

Choose a reason for hiding this comment

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

run-time

@petebacondarwin
Copy link
Member

@timruffles - nice one Tim! A couple of minor documentation points to deal with but it seems good to me.

I think it is also worth updating the testing guide with this new feature (https://docs.angularjs.org/guide/unit-testing)

@timruffles timruffles force-pushed the sharedInjectorBeforeAll branch 3 times, most recently from b7e754a to 8b44322 Compare February 24, 2016 14:18
@timruffles
Copy link
Contributor Author

@petebacondarwin thanks for reviewing. Have updated docs as per your suggestions, and added a section to guide. The fiddles are also updated.

@petebacondarwin
Copy link
Member

Can you run grunt test on the PR and fix the JSCS issues?

Allow to opt-in to using a shared injector within a context. This allows  hooks to be
used in Jasmine 2.x.x/Mocha
@timruffles
Copy link
Contributor Author

@petebacondarwin Yup, fixed! Sorry about that.

@tychedelia
Copy link

Just ran into this bug today and am delighted to see the fix is in. Thanks @timruffles ! 👍

@timruffles
Copy link
Contributor Author

@petebacondarwin let me know if there's anything else you like me to do on this!

@petebacondarwin
Copy link
Member

No problem. I'll deal with it today

petebacondarwin pushed a commit that referenced this pull request Mar 1, 2016
Allow to opt-in to using a shared injector within a context. This allows  hooks to be
used in Jasmine 2.x.x/Mocha

Closes #14093
Closes #10238
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.

None yet

4 participants