Modernize sinon.stub() calls
This commit is contained in:
parent
506b35840e
commit
063e13ef22
|
@ -188,7 +188,7 @@ describe("Zotero.DataDirectory", function () {
|
||||||
yield populateDataDirectory(oldDir, null, automatic);
|
yield populateDataDirectory(oldDir, null, automatic);
|
||||||
|
|
||||||
let origFunc = OS.File.move;
|
let origFunc = OS.File.move;
|
||||||
let fileMoveStub = sinon.stub(OS.File, "move", function () {
|
let fileMoveStub = sinon.stub(OS.File, "move").callsFake(function () {
|
||||||
if (OS.Path.basename(arguments[0]) == storageFile1) {
|
if (OS.Path.basename(arguments[0]) == storageFile1) {
|
||||||
return Zotero.Promise.reject(new Error("Error"));
|
return Zotero.Promise.reject(new Error("Error"));
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ describe("Zotero.DataDirectory", function () {
|
||||||
yield populateDataDirectory(oldDir, null, automatic);
|
yield populateDataDirectory(oldDir, null, automatic);
|
||||||
|
|
||||||
let origFunc = OS.File.move;
|
let origFunc = OS.File.move;
|
||||||
let stub1 = sinon.stub(OS.File, "move", function () {
|
let stub1 = sinon.stub(OS.File, "move").callsFake(function () {
|
||||||
if (OS.Path.basename(arguments[0]) == dbFilename) {
|
if (OS.Path.basename(arguments[0]) == dbFilename) {
|
||||||
return Zotero.Promise.reject(new Error("Error"));
|
return Zotero.Promise.reject(new Error("Error"));
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,7 @@ describe("Zotero.DataDirectory", function () {
|
||||||
yield populateDataDirectory(oldDir);
|
yield populateDataDirectory(oldDir);
|
||||||
|
|
||||||
let origFunc = OS.File.move;
|
let origFunc = OS.File.move;
|
||||||
let stub1 = sinon.stub(OS.File, "move", function () {
|
let stub1 = sinon.stub(OS.File, "move").callsFake(function () {
|
||||||
if (OS.Path.basename(arguments[0]) == storageFile1) {
|
if (OS.Path.basename(arguments[0]) == storageFile1) {
|
||||||
return Zotero.Promise.reject(new Error("Error"));
|
return Zotero.Promise.reject(new Error("Error"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,14 +300,20 @@ describe("Zotero.Integration", function () {
|
||||||
}
|
}
|
||||||
setAddEditItems(testItems[0]);
|
setAddEditItems(testItems[0]);
|
||||||
|
|
||||||
sinon.stub(Zotero.Integration, 'getApplication', function(agent, command, docID) {
|
sinon.stub(Zotero.Integration, 'getApplication').callsFake(function(agent, command, docID) {
|
||||||
if (!applications[docID]) {
|
if (!applications[docID]) {
|
||||||
applications[docID] = new DocumentPluginDummy.Application();
|
applications[docID] = new DocumentPluginDummy.Application();
|
||||||
}
|
}
|
||||||
return applications[docID];
|
return applications[docID];
|
||||||
});
|
});
|
||||||
|
|
||||||
displayDialogStub = sinon.stub(Zotero.Integration, 'displayDialog', function(doc, dialogName, prefs, io) {
|
displayDialogStub = sinon.stub(Zotero.Integration, 'displayDialog',
|
||||||
|
// @TODO: This sinon.stub syntax is deprecated!
|
||||||
|
// However when using callsFake tests won't work. This is due to a
|
||||||
|
// possible bug that reset() erases callsFake.
|
||||||
|
// @NOTE: https://github.com/sinonjs/sinon/issues/1341
|
||||||
|
// displayDialogStub.callsFake(function(doc, dialogName, prefs, io) {
|
||||||
|
function(doc, dialogName, prefs, io) {
|
||||||
var ioResult = dialogResults[dialogName.substring(dialogName.lastIndexOf('/')+1, dialogName.length-4)];
|
var ioResult = dialogResults[dialogName.substring(dialogName.lastIndexOf('/')+1, dialogName.length-4)];
|
||||||
if (typeof ioResult == 'function') {
|
if (typeof ioResult == 'function') {
|
||||||
ioResult = ioResult(doc, dialogName);
|
ioResult = ioResult(doc, dialogName);
|
||||||
|
@ -389,7 +395,7 @@ describe("Zotero.Integration", function () {
|
||||||
var styleInstallStub = sinon.stub(Zotero.Styles, "install").resolves();
|
var styleInstallStub = sinon.stub(Zotero.Styles, "install").resolves();
|
||||||
var style = Zotero.Styles.get(styleID);
|
var style = Zotero.Styles.get(styleID);
|
||||||
var styleGetCalledOnce = false;
|
var styleGetCalledOnce = false;
|
||||||
var styleGetStub = sinon.stub(Zotero.Styles, 'get', function() {
|
var styleGetStub = sinon.stub(Zotero.Styles, 'get').callsFake(function() {
|
||||||
if (!styleGetCalledOnce) {
|
if (!styleGetCalledOnce) {
|
||||||
styleGetCalledOnce = true;
|
styleGetCalledOnce = true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -422,7 +428,7 @@ describe("Zotero.Integration", function () {
|
||||||
var styleInstallStub = sinon.stub(Zotero.Styles, "install").resolves();
|
var styleInstallStub = sinon.stub(Zotero.Styles, "install").resolves();
|
||||||
var style = Zotero.Styles.get(styleID);
|
var style = Zotero.Styles.get(styleID);
|
||||||
var styleGetCalledOnce = false;
|
var styleGetCalledOnce = false;
|
||||||
var styleGetStub = sinon.stub(Zotero.Styles, 'get', function() {
|
var styleGetStub = sinon.stub(Zotero.Styles, 'get').callsFake(function() {
|
||||||
if (!styleGetCalledOnce) {
|
if (!styleGetCalledOnce) {
|
||||||
styleGetCalledOnce = true;
|
styleGetCalledOnce = true;
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -464,7 +464,7 @@ describe("Connector Server", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should import a style with application/vnd.citationstyles.style+xml content-type', function* () {
|
it('should import a style with application/vnd.citationstyles.style+xml content-type', function* () {
|
||||||
sinon.stub(Zotero.Styles, 'install', function(style) {
|
sinon.stub(Zotero.Styles, 'install').callsFake(function(style) {
|
||||||
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
|
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
|
||||||
.createInstance(Components.interfaces.nsIDOMParser),
|
.createInstance(Components.interfaces.nsIDOMParser),
|
||||||
doc = parser.parseFromString(style, "application/xml");
|
doc = parser.parseFromString(style, "application/xml");
|
||||||
|
|
|
@ -286,7 +286,7 @@ describe("Zotero.Sync.Storage.Local", function () {
|
||||||
|
|
||||||
// Stub functions to simulate OS.Path.basename() behavior on Windows
|
// Stub functions to simulate OS.Path.basename() behavior on Windows
|
||||||
var basenameOrigFunc = OS.Path.basename.bind(OS.Path);
|
var basenameOrigFunc = OS.Path.basename.bind(OS.Path);
|
||||||
var basenameStub = sinon.stub(OS.Path, "basename", (path) => {
|
var basenameStub = sinon.stub(OS.Path, "basename").callsFake((path) => {
|
||||||
// Split on colon
|
// Split on colon
|
||||||
if (path.endsWith("a:b.txt")) {
|
if (path.endsWith("a:b.txt")) {
|
||||||
return "b.txt";
|
return "b.txt";
|
||||||
|
@ -294,7 +294,7 @@ describe("Zotero.Sync.Storage.Local", function () {
|
||||||
return basenameOrigFunc(path);
|
return basenameOrigFunc(path);
|
||||||
});
|
});
|
||||||
var pathToFileOrigFunc = Zotero.File.pathToFile.bind(Zotero.File);
|
var pathToFileOrigFunc = Zotero.File.pathToFile.bind(Zotero.File);
|
||||||
var pathToFileStub = sinon.stub(Zotero.File, "pathToFile", (path) => {
|
var pathToFileStub = sinon.stub(Zotero.File, "pathToFile").callsFake((path) => {
|
||||||
if (path.includes(":")) {
|
if (path.includes(":")) {
|
||||||
throw new Error("Path contains colon");
|
throw new Error("Path contains colon");
|
||||||
}
|
}
|
||||||
|
@ -476,7 +476,7 @@ describe("Zotero.Sync.Storage.Local", function () {
|
||||||
|
|
||||||
// Stub functions to simulate OS.Path.basename() behavior on Windows
|
// Stub functions to simulate OS.Path.basename() behavior on Windows
|
||||||
var basenameOrigFunc = OS.Path.basename.bind(OS.Path);
|
var basenameOrigFunc = OS.Path.basename.bind(OS.Path);
|
||||||
var basenameStub = sinon.stub(OS.Path, "basename", (path) => {
|
var basenameStub = sinon.stub(OS.Path, "basename").callsFake((path) => {
|
||||||
// Split on colon
|
// Split on colon
|
||||||
if (path.endsWith("a:b.html")) {
|
if (path.endsWith("a:b.html")) {
|
||||||
return "b.html";
|
return "b.html";
|
||||||
|
@ -484,7 +484,7 @@ describe("Zotero.Sync.Storage.Local", function () {
|
||||||
return basenameOrigFunc(path);
|
return basenameOrigFunc(path);
|
||||||
});
|
});
|
||||||
var pathToFileOrigFunc = Zotero.File.pathToFile.bind(Zotero.File);
|
var pathToFileOrigFunc = Zotero.File.pathToFile.bind(Zotero.File);
|
||||||
var pathToFileStub = sinon.stub(Zotero.File, "pathToFile", (path) => {
|
var pathToFileStub = sinon.stub(Zotero.File, "pathToFile").callsFake((path) => {
|
||||||
if (path.includes(":")) {
|
if (path.includes(":")) {
|
||||||
throw new Error("Path contains colon");
|
throw new Error("Path contains colon");
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ describe("Zotero.Styles", function() {
|
||||||
|
|
||||||
it("should install the style from url", function* () {
|
it("should install the style from url", function* () {
|
||||||
var getContentsFromURLAsync = Zotero.File.getContentsFromURLAsync;
|
var getContentsFromURLAsync = Zotero.File.getContentsFromURLAsync;
|
||||||
sinon.stub(Zotero.File, 'getContentsFromURLAsync', function(style) {
|
sinon.stub(Zotero.File, 'getContentsFromURLAsync').callsFake(function(style) {
|
||||||
if (style.url == styleID) {
|
if (style.url == styleID) {
|
||||||
return Zotero.Promise.resolve(style);
|
return Zotero.Promise.resolve(style);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user