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

Serialize Wrapper Instances #4

Merged
merged 2 commits into from May 24, 2018
Merged

Serialize Wrapper Instances #4

merged 2 commits into from May 24, 2018

Conversation

dvdzkwsk
Copy link
Contributor

Thanks for this project!

I stumbled upon this after a friend noticed hugely inflated snapshot sizes in his codebase, where developers were forgetting to call .html() in their snapshot assertions.

Digging into it, I noticed that the current implementation requires the user to call .html() before passing the wrapper in. It seems like this should be the primary concern of the serializer, since the purpose of configuring a global serializer such as this is to remove the burden of manually doing it in every assertion. This is how Enzyme's popular toJSON serializer works, for example.

This would likely be a major version upgrade since it would break snapshots for anybody that was inadvertently snapshotting entire instances.

Thanks in advance for taking a look :)

index.js Outdated
@@ -1,11 +1,15 @@
const beautify = require('pretty')

const isHtmlString = received => typeof received === 'string' && received[0] === '<'
const isVueWrapper = received => typeof received === 'object' && received.isVueComponent
Copy link
Owner

Choose a reason for hiding this comment

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

This property will soon be renamed to isVm. Instead use the public method isVueInstance()

Copy link
Contributor Author

@dvdzkwsk dvdzkwsk May 24, 2018

Choose a reason for hiding this comment

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

Got it, wasn't aware of that. Will do.

Copy link
Owner

@eddyerburgh eddyerburgh left a comment

Choose a reason for hiding this comment

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

Looks great 👍 . As you said, this will be a breaking change for people who are creating a snapshot from a wrapper object

index.js Outdated
const isVueWrapper = received => (
typeof received === 'object' &&
received.isVueInstance &&
received.isVueInstance()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eddyerburgh I made the change as you suggested. I am wondering if you think it's necessary to actually call isVueInstance when the existence of the method is already Vue-specific. I put both the existence check and the call in for now, but will defer to your judgement.

@dvdzkwsk
Copy link
Contributor Author

dvdzkwsk commented May 24, 2018

Thanks for taking a look so quickly. I made the change as you suggested and squashed it back in. There's one question I had about your preferred usage, but other than that it should be good to go.

index.js Outdated
const isHtmlString = received => typeof received === 'string' && received[0] === '<'
const isVueWrapper = received => (
typeof received === 'object' &&
typeof received.isVueInstance === 'function' &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eddyerburgh I made the change as you suggested. I am wondering if you think it's necessary to actually call isVueInstance when the existence of the method is already Vue-specific. That is, of course, assuming this method will always return true. I put both the existence check and the call in for now, but will defer to your judgement.

(Repeating this comment due to the previous one being shown as outdated due to a squashed commit).

Copy link
Owner

Choose a reason for hiding this comment

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

Good point, the existence is enough 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, thanks. I've pushed that change.

Copy link
Owner

@eddyerburgh eddyerburgh left a comment

Choose a reason for hiding this comment

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

Thanks 👍

@eddyerburgh eddyerburgh merged commit 3e8dec0 into eddyerburgh:master May 24, 2018
@dvdzkwsk dvdzkwsk deleted the feat/serialize-wrapper-instances branch May 24, 2018 23:16
@eddyerburgh
Copy link
Owner

This has been released in v2.0.0

@dvdzkwsk
Copy link
Contributor Author

Awesome! I now realize that one change I forgot to make as part of this PR was updating the example in the README to reflect the new usage.

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.

None yet

2 participants