@@ -15,21 +15,30 @@ describe('String', () => {
15
15
it ( '.match global' , ( ) => {
16
16
const result = 'test' . match ( createRegExp ( char . as ( 'foo' ) , [ global ] ) )
17
17
expect ( Array . isArray ( result ) ) . toBeTruthy ( )
18
+ // @ts -expect-error
18
19
expect ( result ?. groups ) . toBeUndefined ( )
19
- // TODO: https://github.com/danielroe/magic-regexp/issues/26
20
- // expectTypeOf(result).toEqualTypeOf<null | string[]>()
20
+ expectTypeOf ( result ) . toEqualTypeOf < null | string [ ] > ( )
21
21
} )
22
22
it . todo ( '.matchAll non-global' , ( ) => {
23
- // TODO: @ts -expect-error
24
- 'test' . matchAll ( createRegExp ( char . as ( 'foo' ) ) )
23
+ // should be deprecated
24
+ expectTypeOf ( 'test' . matchAll ( createRegExp ( char . as ( 'foo' ) ) ) ) . toEqualTypeOf < never > ( )
25
+ expectTypeOf ( 'test' . matchAll ( createRegExp ( char . as ( 'foo' ) , [ 'm' ] ) ) ) . toEqualTypeOf < never > ( )
25
26
} )
26
27
it ( '.matchAll global' , ( ) => {
27
28
const results = 'test' . matchAll ( createRegExp ( char . as ( 'foo' ) , [ global ] ) )
28
- expect ( Array . isArray ( [ ... results ] ) ) . toBeTruthy ( )
29
+ let count = 0
29
30
for ( const result of results ) {
30
- expect ( result ?. groups ) . toBeUndefined ( )
31
- // TODO: https://github.com/danielroe/magic-regexp/issues/26
32
- // expectTypeOf(result).toEqualTypeOf<null | string[]>()
31
+ count ++
32
+ expect ( [ ...'test' ] . includes ( result ?. groups . foo || '' ) ) . toBeTruthy ( )
33
+ expectTypeOf ( result ) . toEqualTypeOf <
34
+ MagicRegExpMatchArray < MagicRegExp < '/(?<foo>.)/g' , 'foo' , 'g' > >
35
+ > ( )
33
36
}
37
+ expect ( count ) . toBe ( 4 )
38
+ } )
39
+ it . todo ( '.replaceAll non-global' , ( ) => {
40
+ // should be deprecated
41
+ expectTypeOf ( 'test' . replaceAll ( createRegExp ( char . as ( 'foo' ) ) , '' ) ) . toEqualTypeOf < never > ( )
42
+ expectTypeOf ( 'test' . replaceAll ( createRegExp ( char . as ( 'foo' ) , [ 'm' ] ) , '' ) ) . toEqualTypeOf < never > ( )
34
43
} )
35
44
} )
0 commit comments