Skip to content

Commit

Permalink
test: cover last branch chrome utils
Browse files Browse the repository at this point in the history
  • Loading branch information
iamogbz committed Apr 17, 2019
1 parent e9cd535 commit 84292dc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tests/utils/chrome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ describe("chrome", () => {
afterEach(chrome.flush);

const expectToHaveBeenCalledWith = (stub: any, ...args: any[]) => {
expect(stub.withArgs(...args).calledOnce).toBe(true);
try {
expect(stub.withArgs(...args).calledOnce).toBe(true);
} catch (e) {
const prettyArgs = JSON.stringify(args).slice(1, -1);
e.message = `Expected: ${stub}(${prettyArgs})\nReceived: nothing`;
throw e;
}
};

describe("commands", () => {
Expand Down Expand Up @@ -105,12 +111,13 @@ describe("chrome", () => {
const tabs = [8, 9, 10].map(
(id, index) => ({ id, index, windowId } as ChromeTab),
);
tabs.push({ id: 1, windowId } as ChromeTab);
const moveTabsPromise = moveTabsToWindow(tabs, windowId);
chrome.tabs.move.yield();
await moveTabsPromise;
tabs.forEach((t, i) =>
expectToHaveBeenCalledWith(chrome.tabs.move, t.id, {
index: i,
tabs.forEach(({ id, index }) =>
expectToHaveBeenCalledWith(chrome.tabs.move, id, {
index: index === undefined ? -1 : index,
windowId,
}),
);
Expand Down

0 comments on commit 84292dc

Please sign in to comment.