Skip to content

storage.getall() fails with jest-webextension-mock due to missing null argument #30

@shuntksh

Description

@shuntksh

Hi Plasmo team,

Firstly, I want to thank you for your work on this library. Really impressive and an excellent DX so far!

I encountered a minor issue while using @plasmohq/storage with jest-webextension-mock. When using storage.getall(), the test fails as the underlying chrome.storage[area].get method is called without an argument, and that causes the jest-webextension-mock to throw with "Wrong key given."

According to the Chrome documentation, to retrieve the entire contents of storage, chrome.storage[area].get seem to expect a null as an argument to return all entries inside. However, the current implementation in @plasmohq/storage (source) calls the underlying method with no argument, which seems to work fine in today's Chrome implementation.

However, jest-webextension-mock expects chrome.storage[area].get to be called explicitly with null to return all values (source) which follows documented behavior. And this causes tests using @plasmohq/storage's storage.getall() to fail.

While both implementations seem correct, I am leaning towards an issue in the implementation of @plasmohq/storage, as it relies on Chrome's undocumented behavior. However, I understand this is not an issue for the library, too, as it works fine today.

As a workaround, I have written my mock to circumvent this issue by accepting an empty argument in chrome.storage[area].prototype.get. I am happy to open a bug report to the mock if you think this is a non-issue for the library or contribute to this library with fixes and tests.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions