Skip to content

Commit f2eff0d

Browse files
committed
Test DB Object with JSON toString(), stringify() and literals
1 parent af60fa2 commit f2eff0d

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

test/dbObject10.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,36 @@ describe('209. dbObject10.js', () => {
105105
should.not.exist(err);
106106
}
107107
}); // 209.1
108+
109+
it('209.2 By default, JavaScript Object toString() returns "[object type]"', async () => {
110+
try {
111+
let result = await conn.execute(`SELECT contact FROM ${TABLE}`);
112+
let dbObj = result.rows[0][0];
113+
114+
let expect = `[object ${dbconfig.user.toUpperCase()}.${TYPE}]`;
115+
should.strictEqual(dbObj.toString(), expect);
116+
117+
expect = '[object Object]';
118+
should.strictEqual(dbObj._toPojo().toString(), expect);
119+
} catch (err) {
120+
should.not.exist(err);
121+
}
122+
}); // 209.2
123+
124+
it('209.3 The Object literal and JSON.stringify()', async () => {
125+
try {
126+
let result = await conn.execute(`SELECT contact FROM ${TABLE}`);
127+
let dbObj = result.rows[0][0];
128+
129+
let expect = `x[HR.NODB_PERSON_TYP] { IDNO: 65,\n FIRST_NAME: 'Verna',\n LAST_NAME: 'Mills',\n EMAIL: '[email protected]',\n PHONE: '1-650-555-0125' }`;
130+
let actual = 'x' + dbObj;
131+
should.strictEqual(actual, expect);
132+
133+
expect = '{"IDNO":65,"FIRST_NAME":"Verna","LAST_NAME":"Mills","EMAIL":"[email protected]","PHONE":"1-650-555-0125"}';
134+
actual = JSON.stringify(dbObj);
135+
should.strictEqual(actual, expect);
136+
} catch (err) {
137+
should.not.exist(err);
138+
}
139+
}); // 209.3
108140
});

test/list.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4557,4 +4557,6 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
45574557
208.7 DML RETURNING INTO and executeMany()
45584558

45594559
209. dbObject10.js
4560-
209.1 DB Objects which contain PL/SQL methods
4560+
209.1 DB Objects which contain PL/SQL methods
4561+
209.2 By default, JavaScript Object toString() returns "[object type]"
4562+
209.3 The Object literal and JSON.stringify()

0 commit comments

Comments
 (0)