Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More opinions on mock organization #109

Merged
merged 1 commit into from
Jun 29, 2016
Merged

More opinions on mock organization #109

merged 1 commit into from
Jun 29, 2016

Conversation

kwv
Copy link
Contributor

@kwv kwv commented Jun 28, 2016

@lathonez the reorg (#103) minimizes boilerplate, but please consider this alternative. For my app at least, putting all of the public methods for 30+ services in a single file is impracticable. When testing services consumed by multiple components, moving the mock out of the spec is DRYer. Ionic/platform mocks are still centrally in the test/mocks.ts but service mocks are in the same directory as the implementation.

To make life easier I'm using barrels to provide encapsulation of services (definition) (import)

I think the same approach makes importing mocks easy as well

services/
   - index.ts /* barrel of all subfolders */
   - clickers/    
      - clickers.service.ts
      - clickers.mock.ts
      - clickers.spec.ts
   - mocks.ts /* barrel of all mocks within subfolders */

@codecov-io
Copy link

Current coverage is 95.50%

Merging #109 into master will decrease coverage by 1.27%

@@             master       #109   diff @@
==========================================
  Files             9         12     +3   
  Lines           186        200    +14   
  Methods          12         12          
  Messages          0          0          
  Branches         28         30     +2   
==========================================
+ Hits            180        191    +11   
- Misses            2          4     +2   
- Partials          4          5     +1   

Powered by Codecov. Last updated by f702378...0e027d4

@lathonez
Copy link
Owner

lathonez commented Jun 28, 2016

@kwv this is glorious, I'd not seen barrels before.

Such contributions make this project very worthwhile for me, thank you.

One question - should clickers.mock.ts be split into two files (+ clicker.mock.ts) to correctly follow this pattern? Or are you grouping all services into one file? The reason I ask is implementation on a larger project..

EDIT: definitely should as Clicker is a model not a service
EDIT2: ClickerMock doesn't seem to be used anywhere, will keep it for posterity

TODO (note to self):

  • expand clickers.mock.ts into two files if necessary
  • get everything using barrels
  • remove *mock.ts and index.ts from coverage
  • changelog

@lathonez lathonez merged commit 0e027d4 into lathonez:master Jun 29, 2016
@lathonez
Copy link
Owner

@kwv thanks again, let me know if you've any comments on the changes I made above.

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

Successfully merging this pull request may close these issues.

3 participants