@@ -39,9 +39,7 @@ See [database-js](https://github.com/mlaanderson/database-js) for the full list
39
39
40
40
## Configure
41
41
42
- ### Configuration in CodeceptJS
43
-
44
- In your ` codecept.json ` , include ** DbHelper** in the property ** helpers** :
42
+ In your CodeceptJS configuration file (e.g., ` codecept.conf.js ` , ` codecept.json ` ), include ** DbHelper** in the property ** helpers** :
45
43
46
44
``` js
47
45
...
@@ -59,7 +57,7 @@ In your `codecept.json`, include **DbHelper** in the property **helpers** :
59
57
60
58
### Syntax differences between CodeceptJS 2 and CodeceptJS 3
61
59
62
- In CodeceptJS 2, your callbacks receive an ` I ` argument:
60
+ In CodeceptJS 2, your callbacks receive ` I ` as argument:
63
61
64
62
``` javascript
65
63
Scenario (' test something' , async ( I ) => { // CodeceptJS 2 notation
@@ -81,24 +79,26 @@ See the [CodeceptJS docs](https://github.com/codeceptjs/CodeceptJS/wiki/Upgradin
81
79
82
80
> The following examples are written with ** CodeceptJS 3** .
83
81
84
- The object ` I ` of your tests and events now has to the [ methods described in the API ] ( #api ) .
82
+ Now the object ` I ` ( of your callbacks) has [ new methods ] ( #api ) .
85
83
86
84
#### Example 1
87
85
88
86
``` js
89
87
BeforeSuite ( async ( { I } ) => {
90
- // The first parameter is the key that will hold a reference to the db
88
+ // Connects to a database
89
+ // The first parameter is the key that will hold a reference to the database
91
90
I .connect ( " testdb" , " mysql://root:mypassword@localhost:3306/testdb" );
92
91
} );
93
92
94
93
AfterSuite ( async ( { I } ) => {
95
- await I .removeConnection ( " testdb" ); // also disconnects
94
+ // Disconnects and removes the reference to the database
95
+ await I .removeConnection ( " testdb" );
96
96
} );
97
97
98
98
99
99
Before ( async ( { I } ) => {
100
100
101
- // Deleting all the records from the table 'user'
101
+ // Deletes all the records from the table 'user'
102
102
await I .run ( " testdb" , " DELETE FROM user" );
103
103
104
104
// Inserting some users
@@ -121,12 +121,12 @@ Feature( 'Foo' );
121
121
Scenario ( ' Bar' , async ( { I } ) => {
122
122
123
123
// Queries a user from the database
124
- const results = await I .query ( " testdb" , " SELECT * FROM user WHERE username = ?" , " bob" );
125
- const bob = results[ 0 ];
124
+ const results = await I .query ( " testdb" , " SELECT username, password FROM user WHERE username = ?" , " bob" );
125
+ const user = results[ 0 ]; // object in the first row
126
126
127
127
I .amOnPage ( ' /login' );
128
- I .fillField ( ' #username' , bob .username );
129
- I .fillField ( ' #password' , bob .password );
128
+ I .fillField ( ' #username' , user .username ); // bob
129
+ I .fillField ( ' #password' , user .password ); // 654321
130
130
I .click ( ' #ok' );
131
131
I .see ( ' Welcome' );
132
132
} );
@@ -137,47 +137,47 @@ Scenario( 'Bar', async( { I } ) => {
137
137
138
138
``` js
139
139
/**
140
- * Connects to a database by the given connection data .
140
+ * Connects to the database described by the given connection string .
141
141
*
142
- * @param {string|number} key Key used to identify the database
143
- * @param {string|object} conn JDBC-like connection string or a connection object accepted by `database-js`.
144
- * @param {object|undefined} driver Driver object, used by `database-js` (optional) .
142
+ * @param {string|number} key Identification for using in other commands.
143
+ * @param {string|object} conn JDBC-like connection string or a connection object accepted by `database-js`.
144
+ * @param {object|undefined} driver [OPTIONAL] Driver object, used by `database-js`.
145
145
*/
146
146
connect ( key, conn, driver );
147
147
148
148
/**
149
- * Disconnects from a given database by its key.
149
+ * Disconnects from the database identified by the given key.
150
150
*
151
- * @param {string|number} key Key used to identify the database
151
+ * @param {string|number} key Database identification key set in connect()
152
152
*/
153
153
async disconnect ( key );
154
154
155
155
/**
156
- * Disconnects and removes a database connection by its key.
156
+ * Disconnects and removes the database connection identified by the given key.
157
157
*
158
- * @param {string|number} key Key used to identify the database
158
+ * @param {string|number} key Database identification key set in connect()
159
159
*/
160
160
async removeConnection ( key );
161
161
162
162
/**
163
- * Queries a database with the given key .
163
+ * Performs a query .
164
164
*
165
- * @param {string|number} key Key used to identify the database
166
- * @param {string} command Query
167
- * @param {any[]} params Parameters of the query
165
+ * @param {string|number} key Database identification key set in connect()
166
+ * @param {string} command Query to run.
167
+ * @param {any[]} params [OPTIONAL] Query parameters
168
168
*
169
- * @returns {Promise<any[]>} The results of the query .
169
+ * @returns {Promise<any[]>} Query results .
170
170
*/
171
171
async query ( key, command, ... params );
172
172
173
173
/**
174
- * Executes a command to the database with the given key .
174
+ * Executes a command.
175
175
*
176
- * @param {string|number} key Key used to identify the database
177
- * @param {string} command Command to execute
178
- * @param {any[]} params Parameters of the command
176
+ * @param {string|number} key Database identification key set in connect()
177
+ * @param {string} command Command to run.
178
+ * @param {any[]} params [OPTIONAL] Command parameters
179
179
*
180
- * @returns {Promise<any[]>}
180
+ * @returns {Promise<any[]>} Command results.
181
181
*/
182
182
async run ( key, command, ... params );
183
183
```
0 commit comments