Skip to content

Add a debug method to screen. #429

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

Merged
merged 2 commits into from
Jan 28, 2020

Conversation

jkdowdle
Copy link
Contributor

@jkdowdle jkdowdle commented Jan 21, 2020

What:
A debug method is being added to the screen object.

Why:
Facilitate debugging tests without having to always modify imports.

How:
Added the debug method to the screen object, following the pattern for the debug method from render in react-testing-library.

Checklist:

Would close
#417

Docs PR:
testing-library/testing-library-docs#362

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 21, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d64f32b:

Sandbox Source
elated-bird-4zikf Configuration

@codecov
Copy link

codecov bot commented Jan 21, 2020

Codecov Report

Merging #429 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #429   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          22     22           
  Lines         374    377    +3     
  Branches       87     88    +1     
=====================================
+ Hits          374    377    +3
Impacted Files Coverage Δ
src/get-queries-for-element.js 100% <ø> (ø) ⬆️
src/screen.js 100% <100%> (ø) ⬆️
src/events.js 100% <0%> (ø) ⬆️

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 a2c3472...d64f32b. Read the comment docs.

@jkdowdle jkdowdle requested a review from kentcdodds January 21, 2020 22:22
@jkdowdle
Copy link
Contributor Author

jkdowdle commented Jan 21, 2020

I am not familiar with adding types, could I get some direction on how to do that? Thank you,

I am thinking of something like this

import { OptionsReceived } from 'pretty-format';

interface ScreenInerface extends Queries {
    debug: (element?: Element | Element[] | HTMLElement | HTMLElement[], maxLength?: number, options?: OptionsReceived) => void;
}

export type Screen<Q extends Queries = typeof queries> = BoundFunctions<Q> & ScreenInterface;

What could I do to add the debug type?

@jkdowdle jkdowdle requested a review from alexkrolick January 21, 2020 22:54
kentcdodds
kentcdodds previously approved these changes Jan 28, 2020
Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

This looks great. Just a few little things in the tests. Thanks!

renderIntoDocument(
`<button>test</button><span>multi-test</span><div>multi-test</div>`,
)
expect(screen.debug).toBeInstanceOf(Function)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we don't need this assertion because we make it implicitly by calling it. Implicit assertions aren't always the best, but when it's something as simple as what type something is I don't think it's all that useful to have.

</div>
</body>"
`)
// log single element
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a console.log.mockClear() between these so that each group of assertions can be more independent from the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That does make it a-lot more clear. Cool, I appreciate this suggestion.

@@ -7,14 +7,19 @@ import * as defaultQueries from './queries'
/**
* @param {HTMLElement} element container
* @param {FuncMap} queries object of functions
* @param {Object} initialValue for reducer
Copy link
Member

Choose a reason for hiding this comment

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

Interesting idea. This probably isn't how I would have done it, but I'm actually pretty cool with it.

@jkdowdle
Copy link
Contributor Author

@kentcdodds suggestions for the tests were added. Thanks!

@jkdowdle jkdowdle requested a review from kentcdodds January 28, 2020 22:14
Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Love it. Thank you!

@kentcdodds kentcdodds merged commit 3805b27 into testing-library:master Jan 28, 2020
@jkdowdle
Copy link
Contributor Author

Love it. Thank you!

Thank you! I appreciate it!

@kentcdodds
Copy link
Member

🎉 This PR is included in version 6.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants