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

Collection of Ionic Mocks for Use in Every Project #21

Open
leifwells opened this issue Apr 1, 2017 · 7 comments
Open

Collection of Ionic Mocks for Use in Every Project #21

leifwells opened this issue Apr 1, 2017 · 7 comments

Comments

@leifwells
Copy link
Contributor

leifwells commented Apr 1, 2017

EDIT: I just realized that the main place I've grabbed Ionic mock from was the Clicker project. mocks.ts. Thanks to @lathonez for making this file available.

I created this issue to begin a discussion around mock objects in Ionic (and I'm not sure where else to have this discussion).

I've been doing a lot of unit testing lately for an Ionic 2 application. One of the things I've found to be very helpful is that there appear to be many mock objects available out there for use in Ionic unit testing. I've put together a few objects that I've needed in a current project into one file so that I can reference them. Take a look.

FYI:

  1. While I have made adjustments to this code, it is not mine. I've found these objects sprinkled over Stack Overflow and else where.
  2. These mocks are working for me, but Your Mileage May Vary.

Here's my issue. For this project, having reliable Ionic mocks is important. We should be unit testing our applications, not the Ionic Framework. There is no reason for each of us to be building their own set of Ionic mocks. As a community, we should be able to assemble these mocks.

Shouldn't we be able to provide mocks for as many of the Ionic pieces that may be needed?

Shouldn't we be able to provide best practices as to where to place these mocks and how to use them?

Re: Best practices: Currently, I have three files in my project:

  • src/testing/mock-ionic.ts: Ionic mocks
  • src/testing/mock-app.ts: mocks of object created in my project
  • src/testing/mock-data.ts: mock data that I can use with my mock services

This is how I've organized my current project. Again, YMMV.

Let the discussion begin.

@kamok
Copy link

kamok commented Apr 3, 2017

I'm reluctant to put all my mocks into a single .ts file. I like having a mocks dir, with 2 sub dirs of ionic and providers. Ionic dir for all their quirky little mocks and providers dir for my own providers that makes HTTP calls.

@leifwells
Copy link
Contributor Author

Thanks for your input, @kamok. It is good to hear how other people organize their unit testing efforts.

I'm not against creating individual class files for each mock. To me, having them in one file makes it convenient for maintenance and versioning.

@jaalzateolaya
Copy link

jaalzateolaya commented May 19, 2017

Hello @leifwells ,

Take a look at ionic-test-doubles, having all this mocks in this template repository may not be useful for components developing.

@stonelasley
Copy link

Hey guys just stumbled on this comment. I was having a very similar issue and ended up creating this project. https://github.com/stonelasley/ionic-mocks.

@lathonez
Copy link
Contributor

lathonez commented Jul 2, 2017

@stonelasley - looks excellent. If you'd have time for a PR on clicker we can increase the userbase for ionic-mocks.

@stonelasley
Copy link

@lathonez that sounds great. I'll do that for sure, clicker has been my go-to reference for many a project.

@davidmpaz
Copy link

Hi I am just starting to dive into the topic. The question that arise to me now is:

What problems could bring only using a mocking library like https://github.com/NagRock/ts-mockito ?

From my point of view, having a set of mocked classes pre built looks to me that keeping them in sync as the framework evolve can be cumbersome. Using the mocking library we will mock just what is needed.

Am i missing something?

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

No branches or pull requests

6 participants