Modernize sinon.stub() calls

This commit is contained in:
Tom Najdek 2017-05-31 16:44:35 +01:00 committed by Dan Stillman
parent 506b35840e
commit 063e13ef22
5 changed files with 19 additions and 13 deletions

View file

@ -188,7 +188,7 @@ describe("Zotero.DataDirectory", function () {
yield populateDataDirectory(oldDir, null, automatic);
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) {
return Zotero.Promise.reject(new Error("Error"));
}
@ -241,7 +241,7 @@ describe("Zotero.DataDirectory", function () {
yield populateDataDirectory(oldDir, null, automatic);
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) {
return Zotero.Promise.reject(new Error("Error"));
}
@ -371,7 +371,7 @@ describe("Zotero.DataDirectory", function () {
yield populateDataDirectory(oldDir);
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) {
return Zotero.Promise.reject(new Error("Error"));
}

View file

@ -300,14 +300,20 @@ describe("Zotero.Integration", function () {
}
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]) {
applications[docID] = new DocumentPluginDummy.Application();
}
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)];
if (typeof ioResult == 'function') {
ioResult = ioResult(doc, dialogName);
@ -389,7 +395,7 @@ describe("Zotero.Integration", function () {
var styleInstallStub = sinon.stub(Zotero.Styles, "install").resolves();
var style = Zotero.Styles.get(styleID);
var styleGetCalledOnce = false;
var styleGetStub = sinon.stub(Zotero.Styles, 'get', function() {
var styleGetStub = sinon.stub(Zotero.Styles, 'get').callsFake(function() {
if (!styleGetCalledOnce) {
styleGetCalledOnce = true;
return false;
@ -422,7 +428,7 @@ describe("Zotero.Integration", function () {
var styleInstallStub = sinon.stub(Zotero.Styles, "install").resolves();
var style = Zotero.Styles.get(styleID);
var styleGetCalledOnce = false;
var styleGetStub = sinon.stub(Zotero.Styles, 'get', function() {
var styleGetStub = sinon.stub(Zotero.Styles, 'get').callsFake(function() {
if (!styleGetCalledOnce) {
styleGetCalledOnce = true;
return false;

View file

@ -464,7 +464,7 @@ describe("Connector Server", 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"]
.createInstance(Components.interfaces.nsIDOMParser),
doc = parser.parseFromString(style, "application/xml");

View file

@ -286,7 +286,7 @@ describe("Zotero.Sync.Storage.Local", function () {
// Stub functions to simulate OS.Path.basename() behavior on Windows
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
if (path.endsWith("a:b.txt")) {
return "b.txt";
@ -294,7 +294,7 @@ describe("Zotero.Sync.Storage.Local", function () {
return basenameOrigFunc(path);
});
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(":")) {
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
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
if (path.endsWith("a:b.html")) {
return "b.html";
@ -484,7 +484,7 @@ describe("Zotero.Sync.Storage.Local", function () {
return basenameOrigFunc(path);
});
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(":")) {
throw new Error("Path contains colon");
}

View file

@ -27,7 +27,7 @@ describe("Zotero.Styles", function() {
it("should install the style from url", function* () {
var getContentsFromURLAsync = Zotero.File.getContentsFromURLAsync;
sinon.stub(Zotero.File, 'getContentsFromURLAsync', function(style) {
sinon.stub(Zotero.File, 'getContentsFromURLAsync').callsFake(function(style) {
if (style.url == styleID) {
return Zotero.Promise.resolve(style);
} else {