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

Fix problem with a mock resolving a mocked value with Promises #192

Closed
wants to merge 2 commits into from

Commits on Jun 19, 2020

  1. Exclude .then() and .catch() from automatic handling.

    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.
    jlkeesey committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    4a8f06c View commit details
    Browse the repository at this point in the history
  2. Added test for toString() conversion

    Added test to verify that adding "Symbol(Symbol.toPrimitive)" to the
    exclude list will allow toString() conversion to work properly.
    jlkeesey committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    4d3ce94 View commit details
    Browse the repository at this point in the history