Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for browser.windows.* APIs #89

Open
pureooze opened this issue Sep 6, 2018 · 4 comments
Open

Add support for browser.windows.* APIs #89

pureooze opened this issue Sep 6, 2018 · 4 comments
Labels

Comments

@pureooze
Copy link

pureooze commented Sep 6, 2018

First of all thanks for making this library, it seems really promising!

I was trying to use this library in my extension and followed the instructions in the README but I keep getting this error when I run certain tests:

failing-test

I think the issue is just that there are no mocks for this part of the API yet (correct me if I am wrong). Let me know if this is actually an issue or I am just misusing the library.

If it is just a case of missing support, I think we can add it. If you want I can make a PR to add these mocks, I looked over the existing source code and I think I understand how this library works.

Thanks!

@clarkbw
Copy link
Owner

clarkbw commented Sep 6, 2018

If it is just a case of missing support, I think we can add it. If you want I can make a PR to add these mocks, I looked over the existing source code and I think I understand how this library works.

Yes, please do! I'd love a PR to add support. 🔨

@pureooze
Copy link
Author

pureooze commented Sep 8, 2018

I made the mocks for the windows api (see here) but I just had a question about how jest-webextension-mock works 🤔 .

In the documentation for the chrome.tab.get API the callback is passed a Tab object. But when I look in the mocks I see:
export const tabs = { get: jest.fn((id = '', cb = () => {}) => cb({})), ... }

So I have two questions:

  1. If the code being tested actually passes in a callback it will expect a Tab object with certain properties but from what I can tell it will always get an empty object?
  2. How does this deal with the difference between the browser.* and chrome.* APIs? From what I understand the WebExtension API expects promises while the chrome API expects callbacks. So if I understand this correctly if we call browser.tabs.get in our code we wont have anything returned?

@clarkbw
Copy link
Owner

clarkbw commented Sep 18, 2018

If the code being tested actually passes in a callback it will expect a Tab object with certain properties but from what I can tell it will always get an empty object?

I'm guessing you'll need to fix that and it was just stubbed out.

How does this deal with the difference between the browser.* and chrome.* APIs? From what I understand the WebExtension API expects promises while the chrome API expects callbacks. So if I understand this correctly if we call browser.tabs.get in our code we wont have anything returned?

In a number of places where this is a concern we use a pattern like this:

const getDetails = (details, cb) => {
if (cb !== undefined) {
return cb();
}
return Promise.resolve();
};

@ronilitman
Copy link

Any progress on this? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants