Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ionic-mocks

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ionic-mocks

Stubbed and Pre-mocked Ionic2 Objects

  • 0.6.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ionic-mocks

Simple Mocking of common Ionic 2 Dependencies

This project is still very early in development and there are several things to workout. However since this is only meant to be used in your tests it should be safe to pull into a project.

Supported Types

  • ActionSheet
  • ActionSheetController
  • Alert
  • AlertController
  • App
  • Content
  • Config
  • Events
  • Form
  • Haptic
  • InifiniteScroll
  • ItemSliding
  • Keyboard
  • Loading
  • LoadingController
  • Menu
  • MenuController
  • Modal
  • ModalController
  • Platform
  • Popover
  • PopoverController
  • NavController
  • NavParams
  • Tab
  • Tabs
  • Toast
  • ToastController
  • ViewController

Installation

npm install --save-dev ionic-mocks

Examples

import {Events, AlertController} from 'ionic-angular';
import {EventsMock, AlertControllerMock} from 'ionic-mocks';

describe('IonicComponent', () => {

    let events: Events;
    let alertCtrl: AlertController;

    let classUnderTest: MyClassUnderTest;

    beforeEach(() => {

        events = EventsMock.instance();
        alertCtrl = AlertControllerMock.instance();

        classUnderTest = new MyClassUnderTest(events, alertCtrl);
    });


    it('should subscribe to events', () => {
    	expect(events.subscribe).toHaveBeenCalled();
    });

    it('should call alert create', () => {

        classUnderTest.showAlert();

        expect(alertCtrl.create).toHaveBeenCalled();
    });
});

Simple Mocking of dependency return types

import {Events, AlertController, Alert} from 'ionic-angular';
import {EventsMock, AlertControllerMock, AlertMock} from 'ionic-mocks';

describe('IonicComponent', () => {

    let alert: Alert;
    let events: Events;
    let alertCtrl: AlertController;

    let classUnderTest: MyClassUnderTest;

    beforeEach(() => {

        events = EventsMock.instance();
        alert = AlertMock.instance():
        alertCtrl = AlertControllerMock.instance(alert);

        classUnderTest = new MyClassUnderTest(events, alertCtrl);
    });


    it('should call present on alert', (done) => {

        classUnderTest.showAlert().then(() => {
            expect(alert.present).toHaveBeenCalled();
            done();
        });

    });
});
Provide Mocks in TestingModule
TestBed.configureTestingModule({
    imports: [IonicModule, AnotherModule],
    declarations: [MyComponent],
    providers: [
            {provide: ViewController, useFactory: () => ViewControllerMock.instance()}                          
    ]
});

FAQs

Package last updated on 03 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc