Skip to content

Collection of Ionic Mocks for Use in Every Project #21

Open

Description

@leifwells

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.

Activity

  1. kamok commented on Apr 3, 2017

    @kamok

    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.

  2. leifwells commented on Apr 3, 2017

    @leifwells
    ContributorAuthor

    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.

  3. jaalzateolaya commented on May 19, 2017

    @jaalzateolaya

    Hello @leifwells ,

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

  4. stonelasley commented on Jul 2, 2017

    @stonelasley

    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.

  5. lathonez commented on Jul 2, 2017

    @lathonez
    Contributor

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

  6. stonelasley commented on Jul 7, 2017

    @stonelasley

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

  7. davidmpaz commented on May 16, 2018

    @davidmpaz

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions