Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/shell-bson-parser/src/stringify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ const { toJSString } = stringifyModule;

describe('stringify', function () {
describe('toJSString', function () {
it('round-trips a plain object that has its own _bsontype field', function () {
const doc = {
field: { _bsontype: 'Timestamp', high: 'a', low: 'b' },
other: { _bsontype: 'Binary', sub_type: 'c' },
};
const str = toJSString(doc);
assert.ok(str);
assert.deepStrictEqual(parse(str), doc);
});

it('serializes a BSON value that has a non-enumerable own _bsontype', function () {
// bson 4 defines _bsontype this way on Timestamp
const ts = new bson.Timestamp({ t: 1, i: 2 });
Object.defineProperty(ts, '_bsontype', { value: 'Timestamp' });
assert.strictEqual(
toJSString({ ts }, 0),
'{ts:Timestamp({ t: 1, i: 2 })}',
);
});

it('should default to two spaces', function () {
assert.equal(
toJSString({ a: { $exists: true } }),
Expand Down
Loading