New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable12] Fix constructor spy in unit test with Sinon 4.1.3 #7451

Merged
merged 1 commit into from Dec 11, 2017

Conversation

Projects
None yet
3 participants
@MorrisJobke
Member

MorrisJobke commented Dec 11, 2017

Backport of #7433

Fix constructor spy in unit test with Sinon 4.1.3
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 <danxuliu@gmail.com>
@MorrisJobke

This comment has been minimized.

Member

MorrisJobke commented Dec 11, 2017

JSUnit tests succeeded -> merging

@MorrisJobke MorrisJobke merged commit 2bd2835 into stable12 Dec 11, 2017

1 check was pending

continuous-integration/drone/pr this build is pending
Details

@MorrisJobke MorrisJobke deleted the 12-7433 branch Dec 11, 2017

@MorrisJobke MorrisJobke referenced this pull request Jan 8, 2018

Merged

12.0.5 RC1 #7740

13 of 13 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment