You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using unit and end to end tests on my app (with Karma, Jasmine and Protactor by following ionic-unit-testing-example).
Let's say I have a class that calls the actual Ionic Native wrapper for a plugin, but I want to test this component. For tests, I'd like to use the mock for that Ionic Native wrapper, instead of the wrapper itself. Please see the example below:
// My class using an Ionic Native wrapper
import { BLE } from '@ionic-native/ble';
export class ClassToBeTested {
uuid: string
ble: BLE
constructor (uuid) {
this.uuid = uuid
this.ble = new BLE()
}
connect () {
this.ble.connect(this.uuid)
// ...
}
}
// Test:
import { ClassToBeTested } from "../../lib/class_to_be_tested"
describe('ClassToBeTested', () => {
it('can be instantiated', () => {
let instance:ClassToBeTested = new ClassToBeTested("a")
expect(instance instanceof ClassToBeTested).toBe(true)
expect(instance.uuid).toBe("a")
})
it('can connect', () => {
let instance:ClassToBeTested = new ClassToBeTested("a")
expect(instance.connect).not.toThrow()
// This fails: Expected function not to throw, but it threw TypeError: Cannot read property 'ble' of undefined.
})
})
I think that what I need is to use BLEMock instead of BLE when testing. How can this be done?
The text was updated successfully, but these errors were encountered:
I am using unit and end to end tests on my app (with Karma, Jasmine and Protactor by following ionic-unit-testing-example).
Let's say I have a class that calls the actual Ionic Native wrapper for a plugin, but I want to test this component. For tests, I'd like to use the mock for that Ionic Native wrapper, instead of the wrapper itself. Please see the example below:
I think that what I need is to use
BLEMock
instead ofBLE
when testing. How can this be done?The text was updated successfully, but these errors were encountered: