Unit testing service with Capacitor plugin

Hello. :wave:

I’m new to Ionic/Capacitor and in my application, I am using Aparajita’s SecureStorage et BiometricAuth plugins and i’d like to do some unit tests on my service that uses SecureStorage.

I have the Capacitor’s documentation with me, but I’m quite confused since it seems it is written for components and not services. I’m wondering if someone already did something like that, or if it’s not really useful to unit test plugin’s methods?

For now I only tried to test one method, which is setKeyPrefix:

it('should set key prefix', async () => {
      spyOn(service, 'initVault');
      spyOn(SecureStorage, 'setKeyPrefix');
      service.initVault();
      expect(service.initVault).toHaveBeenCalled();
      expect(SecureStorage.setKeyPrefix).toHaveBeenCalledWith('prefix');
    });

But i get an error when running it:

VaultService > #init > should set key prefix
Error: <toHaveBeenCalledWith> : Expected a spy, but got Function.
Usage: expect(<spyObj>).toHaveBeenCalledWith(...arguments)

Thanks! :grinning: