FileHandlers tests: Wait for notifier instead of _setState() call
_setState() doesn't await setAttachmentLastPageIndex(), so the setting sometimes won't be updated in the cache by the time we call getAttachmentLastPageIndex() below. Notifier event should work every time (and is a lot simpler).
This commit is contained in:
parent
9e78957c72
commit
ea63780600
1 changed files with 2 additions and 10 deletions
|
@ -34,20 +34,12 @@ describe("Zotero.FileHandlers", () => {
|
||||||
let reader = Zotero.Reader.getByTabID(win.Zotero_Tabs.selectedID);
|
let reader = Zotero.Reader.getByTabID(win.Zotero_Tabs.selectedID);
|
||||||
assert.ok(reader);
|
assert.ok(reader);
|
||||||
|
|
||||||
// Wait for _setState() (is there an easier way to do this?)
|
let notifierPromise = waitForNotifierEvent('add', 'setting');
|
||||||
let stub = sinon.stub(reader, '_setState');
|
|
||||||
let setStatePromise = new Promise((resolve) => {
|
|
||||||
stub.callsFake(async (...args) => {
|
|
||||||
await stub.wrappedMethod.apply(reader, args);
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
await reader._waitForReader();
|
await reader._waitForReader();
|
||||||
await setStatePromise;
|
await notifierPromise;
|
||||||
|
|
||||||
// Check that the reader navigated to the correct page
|
// Check that the reader navigated to the correct page
|
||||||
assert.equal(pdf.getAttachmentLastPageIndex(), 2);
|
assert.equal(pdf.getAttachmentLastPageIndex(), 2);
|
||||||
stub.restore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should open a PDF in a new window when no handler is set and openInWindow is passed", async function () {
|
it("should open a PDF in a new window when no handler is set and openInWindow is passed", async function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue