@@ -5,15 +5,17 @@ import { instanceOf } from '../instanceOf.js';
55
66describe ( 'instanceOf' , ( ) => {
77 it ( 'do not throw on values without prototype' , ( ) => {
8+ const fooSymbol : unique symbol = Symbol ( 'Foo' ) ;
89 class Foo {
10+ readonly __kind : symbol = fooSymbol ;
911 get [ Symbol . toStringTag ] ( ) {
1012 return 'Foo' ;
1113 }
1214 }
1315
14- expect ( instanceOf ( true , Foo ) ) . to . equal ( false ) ;
15- expect ( instanceOf ( null , Foo ) ) . to . equal ( false ) ;
16- expect ( instanceOf ( Object . create ( null ) , Foo ) ) . to . equal ( false ) ;
16+ expect ( instanceOf ( true , fooSymbol , Foo ) ) . to . equal ( false ) ;
17+ expect ( instanceOf ( null , fooSymbol , Foo ) ) . to . equal ( false ) ;
18+ expect ( instanceOf ( Object . create ( null ) , fooSymbol , Foo ) ) . to . equal ( false ) ;
1719 } ) ;
1820
1921 it ( 'detect name clashes with older versions of this lib' , ( ) => {
@@ -23,56 +25,66 @@ describe('instanceOf', () => {
2325 }
2426
2527 function newVersion ( ) {
26- class Foo {
28+ const fooSymbol : unique symbol = Symbol ( 'Foo' ) ;
29+ class FooClass {
30+ readonly __kind : symbol = fooSymbol ;
2731 get [ Symbol . toStringTag ] ( ) {
2832 return 'Foo' ;
2933 }
3034 }
31- return Foo ;
35+ return { fooSymbol , FooClass } ;
3236 }
3337
34- const NewClass = newVersion ( ) ;
38+ const { fooSymbol : newSymbol , FooClass : NewClass } = newVersion ( ) ;
3539 const OldClass = oldVersion ( ) ;
36- expect ( instanceOf ( new NewClass ( ) , NewClass ) ) . to . equal ( true ) ;
37- expect ( ( ) => instanceOf ( new OldClass ( ) , NewClass ) ) . to . throw ( ) ;
40+ expect ( instanceOf ( new NewClass ( ) , newSymbol , NewClass ) ) . to . equal ( true ) ;
41+ expect ( ( ) => instanceOf ( new OldClass ( ) , newSymbol , NewClass ) ) . to . throw ( ) ;
3842 } ) ;
3943
4044 it ( 'allows instances to have share the same constructor name' , ( ) => {
4145 function getMinifiedClass ( tag : string ) {
46+ const someSymbol : unique symbol = Symbol ( tag ) ;
4247 class SomeNameAfterMinification {
48+ readonly __kind : symbol = someSymbol ;
4349 get [ Symbol . toStringTag ] ( ) {
4450 return tag ;
4551 }
4652 }
47- return SomeNameAfterMinification ;
53+ return { someSymbol , SomeNameAfterMinification } ;
4854 }
4955
50- const Foo = getMinifiedClass ( 'Foo' ) ;
51- const Bar = getMinifiedClass ( 'Bar' ) ;
52- expect ( instanceOf ( new Foo ( ) , Bar ) ) . to . equal ( false ) ;
53- expect ( instanceOf ( new Bar ( ) , Foo ) ) . to . equal ( false ) ;
56+ const { someSymbol : fooSymbol , SomeNameAfterMinification : Foo } =
57+ getMinifiedClass ( 'Foo' ) ;
58+ const { someSymbol : barSymbol , SomeNameAfterMinification : Bar } =
59+ getMinifiedClass ( 'Bar' ) ;
60+ expect ( instanceOf ( new Foo ( ) , barSymbol , Bar ) ) . to . equal ( false ) ;
61+ expect ( instanceOf ( new Bar ( ) , fooSymbol , Foo ) ) . to . equal ( false ) ;
5462
55- const DuplicateOfFoo = getMinifiedClass ( 'Foo' ) ;
56- expect ( ( ) => instanceOf ( new DuplicateOfFoo ( ) , Foo ) ) . to . throw ( ) ;
57- expect ( ( ) => instanceOf ( new Foo ( ) , DuplicateOfFoo ) ) . to . throw ( ) ;
63+ const {
64+ someSymbol : duplicateOfFooSymbol ,
65+ SomeNameAfterMinification : DuplicateOfFoo ,
66+ } = getMinifiedClass ( 'Foo' ) ;
67+ expect ( ( ) => instanceOf ( new DuplicateOfFoo ( ) , fooSymbol , Foo ) ) . to . throw ( ) ;
68+ expect ( ( ) => instanceOf ( new Foo ( ) , duplicateOfFooSymbol , Foo ) ) . to . throw ( ) ;
5869 } ) ;
5970
6071 it ( 'fails with descriptive error message' , ( ) => {
6172 function getFoo ( ) {
73+ const fooSymbol : unique symbol = Symbol ( 'Foo' ) ;
6274 class Foo {
6375 get [ Symbol . toStringTag ] ( ) {
6476 return 'Foo' ;
6577 }
6678 }
67- return Foo ;
79+ return { fooSymbol , Foo } ;
6880 }
69- const Foo1 = getFoo ( ) ;
70- const Foo2 = getFoo ( ) ;
81+ const { fooSymbol : foo1Symbol , Foo : Foo1 } = getFoo ( ) ;
82+ const { fooSymbol : foo2Symbol , Foo : Foo2 } = getFoo ( ) ;
7183
72- expect ( ( ) => instanceOf ( new Foo1 ( ) , Foo2 ) ) . to . throw (
84+ expect ( ( ) => instanceOf ( new Foo1 ( ) , foo2Symbol , Foo2 ) ) . to . throw (
7385 / ^ C a n n o t u s e F o o " { } " f r o m a n o t h e r m o d u l e o r r e a l m ./ m,
7486 ) ;
75- expect ( ( ) => instanceOf ( new Foo2 ( ) , Foo1 ) ) . to . throw (
87+ expect ( ( ) => instanceOf ( new Foo2 ( ) , foo1Symbol , Foo1 ) ) . to . throw (
7688 / ^ C a n n o t u s e F o o " { } " f r o m a n o t h e r m o d u l e o r r e a l m ./ m,
7789 ) ;
7890 } ) ;
0 commit comments