File tree Expand file tree Collapse file tree 2 files changed +25
-21
lines changed Expand file tree Collapse file tree 2 files changed +25
-21
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const BSON = require ( '../register-bson' ) ;
4
+ const BSONTypeError = BSON . BSONTypeError ;
5
+ const BSONError = BSON . BSONError ;
6
+
7
+ describe ( 'BSON error tests' , function ( ) {
8
+ it ( 'should correctly validate instanceof checks for BSONTypeError and BSONError' , function ( ) {
9
+ const bsonTypeErr = new BSONTypeError ( ) ;
10
+ const bsonErr = new BSONError ( ) ;
11
+
12
+ expect ( bsonTypeErr instanceof BSONTypeError ) . to . be . true ;
13
+ expect ( bsonErr instanceof BSONError ) . to . be . true ;
14
+ } ) ;
15
+
16
+ it ( 'should correctly get correct names for BSONTypeError and BSONError' , function ( ) {
17
+ const bsonTypeErr = new BSONTypeError ( 'This is a BSONTypeError message' ) ;
18
+ const bsonErr = new BSONError ( 'This is a BSONError message' ) ;
19
+
20
+ expect ( bsonTypeErr . name ) . equals ( 'BSONTypeError' ) ;
21
+ expect ( bsonTypeErr . message ) . equals ( 'This is a BSONTypeError message' ) ;
22
+ expect ( bsonErr . name ) . equals ( 'BSONError' ) ;
23
+ expect ( bsonErr . message ) . equals ( 'This is a BSONError message' ) ;
24
+ } ) ;
25
+ } ) ;
Original file line number Diff line number Diff line change @@ -14,25 +14,4 @@ require('object.entries/auto');
14
14
const BSON = require ( '../lib/bson' ) ;
15
15
const { ensureBuffer } = require ( '../lib/ensure_buffer' ) ;
16
16
BSON . ensureBuffer = ensureBuffer ;
17
-
18
- const { Assertion, util } = require ( 'chai' ) ;
19
- Assertion . overwriteMethod ( 'throw' , function ( original ) {
20
- return function assertThrow ( ...args ) {
21
- if ( args . length === 0 || args . includes ( BSON . BSONError ) || args . includes ( BSON . BSONTypeError ) ) {
22
- // By default, lets check for BSONError or BSONTypeError
23
- // Since we compile to es5 instanceof is broken???
24
- const assertion = original . apply ( this , args ) ;
25
- const object = util . flag ( assertion , 'object' ) ;
26
- return this . assert (
27
- object && / B S O N E r r o r | B S O N T y p e E r r o r / . test ( object . stack ) ,
28
- 'expected #{this} to be a BSONError or a BSONTypeError but got #{act}' ,
29
- 'expected #{this} to not be a BSONError nor a BSONTypeError but got #{act}' ,
30
- ( object && object . stack ) || '<error undefined>'
31
- ) ;
32
- } else {
33
- return original . apply ( this , args ) ;
34
- }
35
- } ;
36
- } ) ;
37
-
38
17
module . exports = BSON ;
You can’t perform that action at this time.
0 commit comments