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

Exclude forward ref when using deep mount #167

Merged

Conversation

mmarcuccio
Copy link
Contributor

When using deep mount on a component wrapped with a forwardRef, currently enzyme-to-json includes the forwardRef node in the JSON.

Running the test included here without the added check for forwardRef results in the following snapshot:

<ForwardRef
  falsyValue={false}
  value="hi mum"
>
  <div
    className="basic-class undefined"
    onClick={[Function]}
  >
    <div
      className="group"
      id="group-id"
    >
      <span />
      <span
        className="empty"
      />
    </div>
  </div>
</ForwardRef>

Since the deep mode should only include DOM nodes, this PR adds a check to exclude the forwardRef node but include the output of the wrapped component.

@codecov
Copy link

codecov bot commented Apr 30, 2020

Codecov Report

Merging #167 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #167   +/-   ##
=======================================
  Coverage   97.19%   97.19%           
=======================================
  Files           6        6           
  Lines         107      107           
  Branches       41       41           
=======================================
  Hits          104      104           
  Misses          3        3           
Impacted Files Coverage Δ
src/mount.js 100.00% <100.00%> (ø)

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 fd3b939...356c30c. Read the comment docs.

@mmarcuccio mmarcuccio marked this pull request as ready for review April 30, 2020 17:51
@VincentLanglet VincentLanglet requested a review from adriantoine May 2, 2020 12:55
@mmarcuccio
Copy link
Contributor Author

Hi @adriantoine. Just a friendly ping - I was wondering if you had a chance to review this.

@VincentLanglet
Copy link
Collaborator

VincentLanglet commented May 7, 2020

Hi @adriantoine. Just a friendly ping - I was wondering if you had a chance to review this.

If not, ping me, I'll do it.

My only concern is that this PR will break existing snapshot...

@mmarcuccio
Copy link
Contributor Author

Hey @VincentLanglet, just following up on this. Yes, this PR would definitely break existing snapshots. It would be limited to those using mount with deep mode on components using forward refs. However, from reading the documentation, this new behavior is the expected behavior of deep mode.

Would it be worth making an option to opt out of this change via configuration?

@VincentLanglet
Copy link
Collaborator

However, from reading the documentation, this new behavior is the expected behavior of deep mode.

Sorry for the delay.
You convince me.

@VincentLanglet VincentLanglet merged commit 866547a into adriantoine:master May 26, 2020
@VincentLanglet
Copy link
Collaborator

@mmarcuccio 3.5.0 is released.

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.

2 participants