11import * as Metho from './metho.js'
22
33describe ( "metho library" , ( ) => {
4+ it ( "should export a data Symbol" , ( ) => {
5+ expect ( Metho . data ) . toBeTruthy ( )
6+ } )
7+
48 it ( "should augment multiple prototypes" , ( ) => {
5- const nonHash = Symbol ( "No hash" )
6- const constHash = Metho . add (
7- [ Number . prototype , String . prototype ] ,
8- ( ) => nonHash ,
9+ const multiFunc = function ( t ) {
10+ return this [ Metho . data ] + ' --- ' + t
11+ }
12+ const multi = Metho . add (
13+ [ Array . prototype , String . prototype ] ,
14+ multiFunc ,
15+ { symbolName : "kumquat" } ,
916 )
1017
11- expect ( 12345 [ constHash ] ) . toBe ( nonHash )
12- expect ( "this is a string" [ constHash ] ) . toBe ( nonHash )
18+ Array . prototype [ Metho . data ] = "array"
19+ String . prototype [ Metho . data ] = "string"
20+
21+ expect ( "Jon" [ multi ( 111 ) ] ) . toBe ( "string --- 111" )
22+ expect ( [ ] [ multi ( 222 ) ] ) . toBe ( "array --- 222" )
23+
24+ expect ( JSON . stringify ( multi . targets ) ) . toEqual ( JSON . stringify ( [ [ ] , "" ] ) )
1325 } )
1426
1527 describe ( "add" , ( ) => {
@@ -31,7 +43,7 @@ describe("metho library", () => {
3143 expect ( 65534 [ asHex ] ) . toBe ( "fffe" )
3244 } )
3345
34- it ( "should augment a single prototype (outer )" , ( ) => {
46+ it ( "should augment a single prototype (outerSyntax: false )" , ( ) => {
3547 const chunk = Metho . add (
3648 String . prototype ,
3749 function ( length ) {
@@ -43,7 +55,7 @@ describe("metho library", () => {
4355 . toEqual ( [ "He" , "ll" , "o " , "Wo" , "rl" , "d!" ] )
4456 } )
4557
46- it ( "should augment a single prototype (outer )" , ( ) => {
58+ it ( "should augment a single prototype (outerSyntax: true )" , ( ) => {
4759 const chunk = Metho . add (
4860 String . prototype ,
4961 function ( length ) {
@@ -55,6 +67,17 @@ describe("metho library", () => {
5567 expect ( "Hello World!" [ chunk ] ( 2 ) )
5668 . toEqual ( [ "He" , "ll" , "o " , "Wo" , "rl" , "d!" ] )
5769 } )
70+
71+ it ( "should use the provided symbolName" , ( ) => {
72+ const symbolName = "octal"
73+ const oct = Metho . add (
74+ Number . prototype ,
75+ function oct ( ) { return this . toString ( 8 ) } ,
76+ { symbolName } ,
77+ )
78+
79+ expect ( oct . toString ( ) ) . toBe ( Symbol ( symbolName ) . toString ( ) )
80+ } )
5881 } )
5982
6083 describe ( "addSimple" , ( ) => {
0 commit comments