From b70b38ce31cf7ba63aeec8a3f417ac1c138c9ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Fri, 8 Dec 2017 18:55:38 +0100 Subject: [PATCH] Fix constructor spy in unit test with Sinon 4.1.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a constructor is spied using Sinon it is wrapped by a proxy function, which calls the original constructor when invoked. When "new Foo()" is executed a "Foo" object is created, "Foo" is invoked with the object as "this", and the object is returned as the result of the whole "new" expression. Before Sinon 4.1.3 the proxy called the original constructor directly using the "thisValue" of the spied call; "thisValue" was the object created by the "new" operator that called the proxy. The proxy assigned "thisValue" to "returnValue", so it was also the value returned by the proxy and, in turn, the value returned by the whole "new" expression. Since Sinon 4.1.3 (see pull request 1626) the proxy calls the original constructor using "new" instead of directly. The "thisValue" created by the outermost "new" (the one that called the proxy) is no longer used by the original constructor; the internal "new" creates a new object, which is the one passed to the original constructor and returned by the internal "new" expression. This object is also the value returned by the proxy ("returnValue") and, in turn, the value returned by the whole outermost "new" expression. Thus, now "returnValue" should be used instead of "thisValue" to get the object created by the spied constructor. Signed-off-by: Daniel Calviño Sánchez --- apps/files_sharing/tests/js/shareSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/tests/js/shareSpec.js b/apps/files_sharing/tests/js/shareSpec.js index 893525f756..91060f6a73 100644 --- a/apps/files_sharing/tests/js/shareSpec.js +++ b/apps/files_sharing/tests/js/shareSpec.js @@ -498,7 +498,7 @@ describe('OCA.Sharing.Util tests', function() { var changeHandler = sinon.stub(); fileInfoModel.on('change', changeHandler); - shareTabSpy.getCall(0).thisValue.trigger('sharesChanged', shareModel); + shareTabSpy.getCall(0).returnValue.trigger('sharesChanged', shareModel); expect(changeHandler.calledOnce).toEqual(true); expect(changeHandler.getCall(0).args[0].changed).toEqual({