Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
ionic-mocks-jest-rxjs6
Advanced tools
Readme
Simple test doubles for Ionic using Jasmine Spy Objects and Jest support
npm install --save-dev ionic-mocks-jest
import { AlertController, Events } from 'ionic-angular';
import { AlertControllerMock, EventsMock } 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();
});
});
import { Alert, AlertController, Events } from 'ionic-angular';
import { AlertControllerMock, AlertMock, EventsMock } 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();
});
});
});
TestBed.configureTestingModule({
imports: [IonicModule],
declarations: [MyComponentUnderTest],
providers: [
{ provide: ViewController, useFactory: () => ViewControllerMock.instance() }
]
});
TypeError: jit__object_Object_33 is not a function
error. What does that mean?Answer: This means you've done something wrong. Take a look at this example:
// DO NOT DO THIS
// USING useClass INSTEAD OF useFactory IS INCORRECT
{ provide: App, useClass: AppMock }
// DO NOT DO THIS
// USING useFactory WITHOUT THE FAT ARROW SYNTAX IS INCORRECT
{ provide: App, useFactory: AppMock.instance() }
Make sure you are using the useFactory
property name and using the fat arrow function as the value:
// DO THIS
{ provide: App, useFactory: () => AppMock.instance() }
FAQs
Stubbed and Pre-mocked Ionic Objects
The npm package ionic-mocks-jest-rxjs6 receives a total of 8 weekly downloads. As such, ionic-mocks-jest-rxjs6 popularity was classified as not popular.
We found that ionic-mocks-jest-rxjs6 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.