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: README.md
+79-1Lines changed: 79 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Then a list of two notes are displayed
25
25
```
26
26
### Prerequisites
27
27
-[Visual Studio Code](https://code.visualstudio.com/)
28
-
-[Node.js](Node.jshttps://nodejs.org)
28
+
-[Node.js](https://nodejs.org)
29
29
30
30
### Red - Acceptance Test
31
31
The user story and acceptance criteria above describe a desired customer outcome. The user acceptance test will link this narrative with a high level how. For this tutorial our first application will be a [web application](https://en.wikipedia.org/wiki/Web_application) in [React](https://reactjs.org). The testing framework we will use to test this will be [Cypress](https://www.cypress.io)
@@ -73,4 +73,82 @@ Timed out retrying after 4000ms: Expected to find element: [data-testid=note-nam
73
73
[Code for this section](https://github.com/pairing4good/tdd-amplify-react-/commit/998cf7a3da2af3b30aed14ccea18e6d546e85e61)
74
74
75
75
### Green - Acceptance Test
76
+
Before we proceed let's add a script to run cypress into the `package.json` file in the `scripts` section.
77
+
```js
78
+
"scripts": {
79
+
"start":"react-scripts start",
80
+
"build":"react-scripts build",
81
+
"test":"react-scripts test",
82
+
"eject":"react-scripts eject",
83
+
"cypress:open":"cypress open"
84
+
}
85
+
```
86
+
- Now you can run `npm run cypress:open` to open cypress
87
+
88
+
The first step to making this failing test go green is adding an element with one of the `data-testid`'s to the `src/App.js` file.
89
+
```js
90
+
import'./App.css';
91
+
92
+
functionApp() {
93
+
return (
94
+
<div className="App">
95
+
<input data-testid="note-name-field"/>
96
+
</div>
97
+
);
98
+
}
99
+
100
+
exportdefaultApp;
101
+
```
102
+
- Now the Cypress test fails on the second field
103
+
```
104
+
Timed out retrying after 4000ms: Expected to find element: [data-testid=note-description-field], but never found it.
105
+
```
106
+
- Add the next `input` field and rerun the test
107
+
- Now the Cypress test fails on the submit button
108
+
```
109
+
Timed out retrying after 4000ms: Expected to find element: [data-testid=note-form-submit], but never found it.
110
+
```
111
+
- Add the `button` element with the expected `data-testid`
112
+
```js
113
+
<input data-testid="note-name-field"/>
114
+
<input data-testid="note-description-field"/>
115
+
<button data-testid="note-form-submit"/>
116
+
```
117
+
- Now the Cypress test fails on the missing list of created notes
118
+
```
119
+
Timed out retrying after 4000ms: Expected to find element: [data-testid=test-name-0], but never found it.
120
+
```
121
+
In test driven development we do the simplest thing possible to make a test go green. Once it is green then and only then do we go back and refactor it. In this case, the simplest thing that we can do is hard-code the expected values on the screen.
122
+
```js
123
+
<input data-testid="note-name-field"/>
124
+
<input data-testid="note-description-field"/>
125
+
<button data-testid="note-form-submit"/>
126
+
<p data-testid="test-name-0">test note</p>
127
+
```
128
+
- Now the Cypresss test fails on the note description
129
+
```
130
+
Timed out retrying after 4000ms: Expected to find element: [data-testid=test-description-0], but never found it.
0 commit comments