chrisgriffith / ionic-native-mocks

Ionic Native Mocks are designed to be used as placeholders during development for the actual Ionic Native modules.
205 stars 42 forks source link

`IntelSecurityMock` does not properly assign sub-mock classes. #19

Closed ehorodyski closed 6 years ago

ehorodyski commented 6 years ago

I am not sure why, but when I try to use IntelSecurityMock the properties data and storage use IntelSecurityStorage and IntelSecurityData instead of their mock classes.

Test Code:

describe('EncryptedStorage', () => {
        let encryptedStorage: EncryptedStorage;

        beforeEach(() => {
            TestBed.configureTestingModule({
                providers: [
                    { provide: IntelSecurity, useClass: IntelSecurityMock },
                    { provide: IntelSecurityStorage, useClass: IntelSecurityStorageMock },
                    { provide: IntelSecurityData, useClass: IntelSecurityDataMock },
                    EncryptedStorage
                ]
            });
            encryptedStorage = TestBed.get(EncryptedStorage);
            console.log(encryptedStorage["_intelSecurity"]);
            console.log(encryptedStorage["_intelSecurity"].storage.read({ id: "1" }));
        });

_intelSecurity being EncryptedStorage's injected instance of IntelSecurity.

Logs:

LOG: IntelSecurityMock{storage: IntelSecurityStorage{}, data: IntelSecurityData{}}
WARN: 'Native: tried calling IntelSecurity.read, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'
WARN: 'Native: tried calling IntelSecurity.read, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'
LOG: ZoneAwarePromise{__zone_symbol__state: 0, __zone_symbol__value: 'cordova_not_available'}
LOG: ZoneAwarePromise{__zone_symbol__state: 0, __zone_symbol__value: 'cordova_not_available'}
ehorodyski commented 6 years ago

Figured it out and created a pull-request.

chrisgriffith commented 6 years ago

Thanks for doing that!