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

sendMessage API has an updated signature in the ChromeSDK expecting extensionId, and options missing from the mock #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions __tests__/runtime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('browser.runtime', () => {
const name = 'CONNECT_NAME';
const listener = jest.fn();
browser.runtime.connect(name).onMessage.addListener(listener);
browser.runtime.sendMessage({ test: 'message' }, done);
browser.runtime.sendMessage('id', { test: 'message' }, null, done);
expect(listener).toHaveBeenCalledWith({ test: 'message' });
});
test('getURL', () => {
Expand All @@ -38,16 +38,16 @@ describe('browser.runtime', () => {
test('sendMessage', (done) => {
const callback = jest.fn(() => done());
expect(jest.isMockFunction(browser.runtime.sendMessage)).toBe(true);
browser.runtime.sendMessage({ test: 'message' }, callback);
browser.runtime.sendMessage('id', { test: 'message' }, null, callback);
expect(browser.runtime.sendMessage).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledTimes(1);
browser.runtime.sendMessage({ test: 'message' });
browser.runtime.sendMessage('id', { test: 'message' });
expect(browser.runtime.sendMessage).toHaveBeenCalledTimes(2);
});
test('sendMessage listener', (done) => {
const listener = jest.fn();
browser.runtime.onMessage.addListener(listener);
browser.runtime.sendMessage({ test: 'message' }, done);
browser.runtime.sendMessage('id', { test: 'message' }, null, done);
expect(listener).toHaveBeenCalledWith({ test: 'message' });
});
test('sendMessage promise', () => {
Expand Down
2 changes: 1 addition & 1 deletion dist/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var runtime = {
disconnect: jest.fn()
};
}),
sendMessage: jest.fn(function (message, cb) {
sendMessage: jest.fn(function (extensionId, message, options, cb) {
onMessageListeners.forEach(function (listener) {
return listener(message);
});
Expand Down
2 changes: 1 addition & 1 deletion src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const runtime = {
disconnect: jest.fn(),
};
}),
sendMessage: jest.fn((message, cb) => {
sendMessage: jest.fn((extensionId, message, options, cb) => {
onMessageListeners.forEach((listener) => listener(message));
if (cb !== undefined) {
return cb();
Expand Down