@@ -39,9 +39,7 @@ See [database-js](https://github.com/mlaanderson/database-js) for the full list
3939
4040## Configure
4141
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** :
4543
4644``` js
4745 ...
@@ -59,7 +57,7 @@ In your `codecept.json`, include **DbHelper** in the property **helpers** :
5957
6058### Syntax differences between CodeceptJS 2 and CodeceptJS 3
6159
62- In CodeceptJS 2, your callbacks receive an ` I ` argument:
60+ In CodeceptJS 2, your callbacks receive ` I ` as argument:
6361
6462``` javascript
6563Scenario (' test something' , async ( I ) => { // CodeceptJS 2 notation
@@ -81,24 +79,26 @@ See the [CodeceptJS docs](https://github.com/codeceptjs/CodeceptJS/wiki/Upgradin
8179
8280> The following examples are written with ** CodeceptJS 3** .
8381
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 ) .
8583
8684#### Example 1
8785
8886``` js
8987BeforeSuite ( 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
9190 I .connect ( " testdb" , " mysql://root:mypassword@localhost:3306/testdb" );
9291} );
9392
9493AfterSuite ( async ( { I } ) => {
95- await I .removeConnection ( " testdb" ); // also disconnects
94+ // Disconnects and removes the reference to the database
95+ await I .removeConnection ( " testdb" );
9696} );
9797
9898
9999Before ( async ( { I } ) => {
100100
101- // Deleting all the records from the table 'user'
101+ // Deletes all the records from the table 'user'
102102 await I .run ( " testdb" , " DELETE FROM user" );
103103
104104 // Inserting some users
@@ -121,12 +121,12 @@ Feature( 'Foo' );
121121Scenario ( ' Bar' , async ( { I } ) => {
122122
123123 // 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
126126
127127 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
130130 I .click ( ' #ok' );
131131 I .see ( ' Welcome' );
132132} );
@@ -137,47 +137,47 @@ Scenario( 'Bar', async( { I } ) => {
137137
138138``` js
139139/**
140- * Connects to a database by the given connection data .
140+ * Connects to the database described by the given connection string .
141141 *
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`.
145145 */
146146connect ( key, conn, driver );
147147
148148/**
149- * Disconnects from a given database by its key.
149+ * Disconnects from the database identified by the given key.
150150 *
151- * @param {string|number} key Key used to identify the database
151+ * @param {string|number} key Database identification key set in connect()
152152 */
153153async disconnect ( key );
154154
155155/**
156- * Disconnects and removes a database connection by its key.
156+ * Disconnects and removes the database connection identified by the given key.
157157 *
158- * @param {string|number} key Key used to identify the database
158+ * @param {string|number} key Database identification key set in connect()
159159 */
160160async removeConnection ( key );
161161
162162/**
163- * Queries a database with the given key .
163+ * Performs a query .
164164 *
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
168168 *
169- * @returns {Promise<any[]>} The results of the query .
169+ * @returns {Promise<any[]>} Query results .
170170 */
171171async query ( key, command, ... params );
172172
173173/**
174- * Executes a command to the database with the given key .
174+ * Executes a command.
175175 *
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
179179 *
180- * @returns {Promise<any[]>}
180+ * @returns {Promise<any[]>} Command results.
181181 */
182182async run ( key, command, ... params );
183183```
0 commit comments