ionic3-mocks
Stubbed and Pre-mocked Ionic3 Objects
Last updated 3 years ago by ariadnagomez .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ionic3-mocks 
SYNC missed versions from official npm registry.

Build Status

ionic-mocks

Simple test doubles for Ionic 3+ using Jasmine Spy Objects

This project is still very early in development and there are several things I'm sorting out. 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
  • InfiniteScroll
  • ItemSliding
  • Loading
  • LoadingController
  • Menu
  • MenuController
  • Modal
  • ModalController
  • Platform
  • Popover
  • PopoverController
  • NavController
  • Nav
  • NavParams
  • StatusBar
  • Tab
  • Tabs
  • Toast
  • ToastController
  • ViewController

Native Plugins

  • 3DTouch
  • Keyboard
  • Network
  • Splashscreen
  • Network
  • ScreenOrientation

Installation

npm install --save-dev ionic-mocks

Examples

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

describe('MyClass', () => {

    let events: Events;
    let alertCtrl: AlertController;

    let classUnderTest: MyClass;

    beforeEach(() => {

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

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


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

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

        classUnderTest.showAlert();

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

Pre-mocked return types

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

describe('MyComponent', () => {

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

    let classUnderTest: MyClass;

    beforeEach(() => {

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

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


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

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

    });
});

Override ionic providers in TestingModule

TestBed.configureTestingModule({
    imports: [IonicModule],
    declarations: [MyComponentUnderTest],
    providers: [
            {provide: ViewController, useFactory: () => ViewControllerMock.instance()}
    ]
});

Current Tags

  • 0.11.22                                ...           latest (3 years ago)

17 Versions

  • 0.11.22                                ...           3 years ago
  • 0.11.21                                ...           3 years ago
  • 0.11.20                                ...           3 years ago
  • 0.11.19                                ...           3 years ago
  • 0.11.18                                ...           3 years ago
  • 0.11.17                                ...           3 years ago
  • 0.11.16                                ...           3 years ago
  • 0.11.15                                ...           3 years ago
  • 0.11.14                                ...           3 years ago
  • 0.11.12                                ...           3 years ago
  • 0.11.11                                ...           3 years ago
  • 0.11.9                                ...           3 years ago
  • 0.11.8                                ...           3 years ago
  • 0.11.7                                ...           3 years ago
  • 0.11.6                                ...           3 years ago
  • 0.11.5                                ...           3 years ago
  • 0.11.4                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (15)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |