Skip to content
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

Fixed problem with a mock resolving a mocked value with Promises #5

Merged
merged 3 commits into from
Sep 28, 2021

Conversation

cspotcode
Copy link
Collaborator

Upstream PR: NagRock#194

jlkeesey added 3 commits June 19, 2020 16:17
By default, all symbols except .hasOwnProperty() are stubbed even if
they are not assigned a value. This is to be able to track references to
all invocations. However, the way that Promise.resolve() works, it
checks for the presence of a .then() property and if it is there assumes
that the resolve value is a promise so it tries to get its resolved
value. But this is a mock reference so the stub does not return a
resolved value so the promise never resolves.

This fix excludes .then() and .catch() from automatically creating a
stub so that Promise will not try to resolve it, but the user can still
override the call with a when() clause.

This fix also adds "Symbol(Symbol.toPrimitive)" to the exclude list so
that by default toString() on a mock will return something other than
null.
Added test to verify that adding "Symbol(Symbol.toPrimitive)" to the
exclude list will allow toString() conversion to work properly.
In the prior commit, the location of one of the new tests was in the
wrong location. This prevented the code from working and the coverage
went down. Moved the test to the correct location and everything passes
and the coverage went up-- at least on my computer.
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@6637048). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master       #5   +/-   ##
=========================================
  Coverage          ?   93.46%           
=========================================
  Files             ?       34           
  Lines             ?      658           
  Branches          ?       82           
=========================================
  Hits              ?      615           
  Misses            ?       30           
  Partials          ?       13           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6637048...dc19b3a. Read the comment docs.

});

it("does not create then descriptor for interface", () => {
// given
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given + when comments are redundant

@cspotcode cspotcode merged commit 3958405 into TypeStrong:master Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants