You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: .github/PULL_REQUEST_TEMPLATE.md
+2-1
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ This is a checklist for PR authors. Please make sure to complete all tasks and c
94
94
-[ ] I followed the guidelines as stated in the [Review Guidelines](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md)
95
95
-[ ] I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like `Avatar`, I verified the components using `Avatar` are working as expected)
96
96
-[ ] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
97
-
-[ ] I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
97
+
-[ ] I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
98
98
-[ ] I verified that if a function's arguments changed that all usages have also been updated correctly
99
99
-[ ] If any new file was added I verified that:
100
100
-[ ] The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
@@ -109,6 +109,7 @@ This is a checklist for PR authors. Please make sure to complete all tasks and c
109
109
-[ ] I verified that all the inputs inside a form are aligned with each other.
110
110
-[ ] I added `Design` label and/or tagged `@Expensify/design` so the design team can review the changes.
111
111
-[ ] If a new page is added, I verified it's using the `ScrollView` component to make it scrollable when more elements are added to the page.
112
+
-[ ] I added [unit tests](https://github.com/Expensify/App/blob/main/tests/README.md) for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
112
113
-[ ] If the `main` branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the `Test` steps.
Copy file name to clipboardexpand all lines: contributingGuides/PROPOSAL_TEMPLATE.md
+3
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,9 @@
7
7
### What changes do you think we should make in order to solve the problem?
8
8
<!-- DO NOT POST CODE DIFFS -->
9
9
10
+
### What specific scenarios should we cover in unit tests to prevent reintroducing this issue in the future?
11
+
<!-- Clearly describe the different test cases you recommend adding or updating. Explain how they will ensure the problem is fully covered and that any future changes do not cause a regression. Consider edge cases, input variations, and typical user interactions that could trigger this issue. To get guidance on how to write unit tests, refer to the README.md in the tests folder. -->
12
+
10
13
### What alternative solutions did you explore? (Optional)
11
14
12
15
**Reminder:** Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.
Copy file name to clipboardexpand all lines: contributingGuides/REVIEWER_CHECKLIST.md
+2-1
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@
30
30
-[ ] I verified that this PR follows the guidelines as stated in the [Review Guidelines](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md)
31
31
-[ ] I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like `Avatar`, I verified the components using `Avatar` have been tested & I retested again)
32
32
-[ ] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
33
-
-[ ] I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
33
+
-[ ] I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
34
34
-[ ] If a new component is created I verified that:
35
35
-[ ] A similar component doesn't exist in the codebase
36
36
-[ ] All props are defined accurately and each prop has a `/** comment above it */`
@@ -54,6 +54,7 @@
54
54
-[ ] I verified that all the inputs inside a form are aligned with each other.
55
55
-[ ] I added `Design` label and/or tagged `@Expensify/design` so the design team can review the changes.
56
56
-[ ] If a new page is added, I verified it's using the `ScrollView` component to make it scrollable when more elements are added to the page.
57
+
-[ ] For any bug fix or new feature in this PR, I verified that sufficient [unit tests](https://github.com/Expensify/App/blob/main/tests/README.md) are included to prevent regressions in this flow.
57
58
-[ ] If the `main` branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the `Test` steps.
58
59
-[ ] I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.
Tests aren't always clear about what exactly is being tested. To make this a bit easier we recommend adopting the following format for code comments:
62
+
Comments are just as critical in tests as the tests themselves. They provide context behind why the test was written and what the expected behavior is supposed to be which will benefit the future generations of engineers looking at them. Think about it. When was the last time you saw a unit test and wondered why it was written that way and then you didn't want to touch it because you didn't know if changing the behavior of the test was appropriate or not? It was probably pretty recent :D
63
63
64
-
```
65
-
// Given <initial_condition>
66
-
... code that sets initial condition
64
+
In order to give future engineers the best context for a unit test, follow this guide:
65
+
66
+
1. DO add three sections to every test:
67
+
- "Given" - This introduces the initial condition of the test
68
+
- "When" - Describes what action is being done and the thing that is being tested
69
+
- "Then" - Describes what is expected to happen
67
70
68
-
// When <something_happens>
69
-
... code that does something
71
+
2. DO begin each comment section with the literal words "Given", "When", and "Then", just like the examples below.
72
+
3. DO explain **WHY** the test is doing what it is doing in every comment.
73
+
4. DO NOT explain **WHAT** the code is doing in comments. This information should be self-evident.
74
+
75
+
The format looks like this:
70
76
71
-
// Then <expectation>
72
-
... code that performs the assertion
73
77
```
78
+
// BAD
79
+
// Given an account
80
+
{* code that sets initial condition *}
74
81
75
-
## Example Test
82
+
// When it is closed
83
+
{* code that does something *}
76
84
77
-
```javascript
78
-
HttpUtils.xhr=jest.fn();
79
-
80
-
describe('actions/Report', () => {
81
-
it('adds an optimistic comment', () => {
82
-
// Given an Onyx subscription to a report's `reportActions`
// Then the action set in the Onyx callback should match
103
-
// the comment we left and it will be in a loading state because
104
-
// it's an "optimistic comment"
105
-
expect(action.message[0].text).toBe('Hello!');
106
-
expect(action.isPending).toBe(true);
107
-
});
108
-
});
109
-
});
85
+
// Then the user is logged out
86
+
{* code that performs the assertion *}
87
+
88
+
// GOOD
89
+
// Given an account of a brand new user
90
+
{* code that sets initial condition *}
91
+
92
+
// When the account is closed by clicking on the close account button
93
+
{* code that does something *}
94
+
95
+
// Then the user should be logged out because their account is no longer active
96
+
{* code that performs the assertion *}
110
97
```
111
98
112
99
## When to Write a Test
113
100
114
-
Many of the UI features of our application should go through rigorous testing by you, your PR reviewer, and finally QA before deployment. It's also difficult to maintain UI tests when the UI changes often. Therefore, it's not valuable for us to place every single part of the application UI under test at this time. The manual testing steps should catch most major UI bugs. Therefore, if we are writing any test there should be a **good reason**.
101
+
Many of the UI features of our application should go through rigorous testing by you, your PR reviewer, and finally QA before deployment. However, the code is mature enough now that protecting code against regressions is the top priority.
115
102
116
103
**What's a "good reason" to write a test?**
117
104
105
+
- Any PR that fixes a bug
106
+
- When introducing a new feature, cover as much logic as possible by unit tests
118
107
- Anything that is difficult or impossible to run a manual tests on
119
108
- e.g. a test to verify an outcome after an authentication token expires (which normally takes two hours)
120
109
- Areas of the code that are changing often, breaking often, and would benefit from the resiliency an automated test would provide
0 commit comments