質問

I'm mocking chrome.storage using jasmine's spyOn function like this:

this.fakeChromeStorage = {};
chrome = { storage: { sync: {get: function() {}, set: function() {}}}};
spyOn(chrome.storage.sync, 'get').and.callFake(function(key, callback) {
    callback();
});

But then when my application calls:

console.info(chrome.storage);
console.info(typeof chrome.storage);
console.info(chrome.storage.type);
console.info(typeof chrome.storage.type);

It prints:

[object Object]
object
undefined
undefined

How is this even possible?

役に立ちましたか?

解決

Yes, chrome.storage is an Object, chrome.storage.type is a property on the object chrome.storage which does not exists and therefor will be undefined.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top