Closed ap1969 closed 6 years ago
One further update: the console does also present the following warning:
"Native: tried calling Network.type, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator"
I'm guessing this implies it's still somehow referencing the non-mocked class?
Andy
Hi,
OK, I think I got this sorted. There were two issues:
I was using the network.d.ts file, not the source .ts file.
I had to add proper getters to mock the properties:
export class NetworkMock extends Network {
/**
* Connection type
* The `type` property will return one of the following connection types: `unknown`, `ethernet`, `wifi`, `2g`, `3g`, `4g`, `cellular`, `none`
* @return {string}
*/
type: '3g';
get type():string {
return '4g';
}
....
Closing issue
Hi, I'm trying to mock the Network plugin, but have encountered issues getting the network.type property. I created a clean project to test the plugin in an isolated mode, and I'm getting the same issue.
The app.component.ts is:
App.module.ts:
package.json:
The console.log("Network: ", network.type); logs null
console.log("Network: ", network); line logs an object with the following structure (apologies for this format, I can't uploage images behind my corp firewall):
As you can see, the 'type' property is part of the proto, not the prototype. I'm using Firefox, if that helps.
Any ideas how I can access the 'type' property succesfully?
Regards, Andy