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

Use consistent test style across codebase #560

Open
LauraBeatris opened this issue Feb 19, 2021 · 1 comment
Open

Use consistent test style across codebase #560

LauraBeatris opened this issue Feb 19, 2021 · 1 comment
Labels
needs specification The desired behavior is not defined yet

Comments

@LauraBeatris
Copy link
Contributor

LauraBeatris commented Feb 19, 2021

In #558 discussions, we've noticed that the test files across the codebase have a mix of declarative and imperative style.

What happened: When contributing for the first time, I didn't know what style to follow while coding the tests since it's mixed across the codebase and there's tool/docs mention to enforce it

The following code is from __tests__/paste.js

// declarative
test('should paste text in textarea', () => { ... }

// imperative
test('does not paste when readOnly', () => { ... }

Reproduction repository: Go through the tests file of the codebase and see a mixture of declarative and imperative styles.

Problem description: Contributors should know whether style to choose, the current situations may cause a lot of confusion and PR discussions

Suggested solution: Discuss in this issue the following topics:

  1. What would be the best test style for this codebase: Declarative or Imperative?
  2. How to enforce a test style?
@LauraBeatris LauraBeatris changed the title style: use consistent test style across codebase Use consistent test style across codebase Feb 19, 2021
@ph-fritsche
Copy link
Member

ph-fritsche commented Mar 16, 2021

After thinking about this both these styles seem good to me - whatever is shorter/more descriptive for the test being written:

test('paste text in textarea')
test('xyz does foo if bar')

Sometimes even a short abstract declaration without any verb might give a better impression what the test is about.
The longer I think about this, the harder I find it to state a preference.

But one other thing becomes clearer:
The modal verb should just adds noise. Of course it should - that's why we're testing it.
When repeated all over again just to stick to this style, it sometimes also causes unnecessarily long and awkward test descriptions that add little to no value to the test code.

So maybe an eslint-rule just warning about modal verbs in test descriptions would be the way to go.

@ph-fritsche ph-fritsche added the needs specification The desired behavior is not defined yet label Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs specification The desired behavior is not defined yet
Projects
None yet
Development

No branches or pull requests

2 participants