File tree 3 files changed +9
-1
lines changed
3 files changed +9
-1
lines changed Original file line number Diff line number Diff line change 50
50
- ` [expect] ` Avoid incorrect difference for subset when ` toMatchObject ` fails ([ #9005 ] ( https://github.com/facebook/jest/pull/9005 ) )
51
51
- ` [expect] ` Consider all RegExp flags for equality ([ #9167 ] ( https://github.com/facebook/jest/pull/9167 ) )
52
52
- ` [expect] ` [ ** BREAKING** ] Consider primitives different from wrappers instantiated with ` new ` ([ #9167 ] ( https://github.com/facebook/jest/pull/9167 ) )
53
+ - ` [expect] ` Prevent maintaining RegExp state between multiple tests ([ #9289 ] ( https://github.com/facebook/jest/pull/9289 ) )
53
54
- ` [expect] ` Fix subsetEquality false circular reference detection ([ #9322 ] ( https://github.com/facebook/jest/pull/9322 ) )
54
55
- ` [jest-config] ` Use half of the available cores when ` watchAll ` mode is enabled ([ #9117 ] ( https://github.com/facebook/jest/pull/9117 ) )
55
56
- ` [jest-config] ` Fix Jest multi project runner still cannot handle exactly one project ([ #8894 ] ( https://github.com/facebook/jest/pull/8894 ) )
Original file line number Diff line number Diff line change @@ -1617,6 +1617,13 @@ describe('.toMatch()', () => {
1617
1617
it ( 'escapes strings properly' , ( ) => {
1618
1618
jestExpect ( 'this?: throws' ) . toMatch ( 'this?: throws' ) ;
1619
1619
} ) ;
1620
+
1621
+ it ( 'does not maintain RegExp state between calls' , ( ) => {
1622
+ const regex = / [ f ] \d + / gi;
1623
+ jestExpect ( 'f123' ) . toMatch ( regex ) ;
1624
+ jestExpect ( 'F456' ) . toMatch ( regex ) ;
1625
+ jestExpect ( regex . lastIndex ) . toBe ( 0 ) ;
1626
+ } ) ;
1620
1627
} ) ;
1621
1628
1622
1629
describe ( '.toHaveLength' , ( ) => {
Original file line number Diff line number Diff line change @@ -835,7 +835,7 @@ const matchers: MatchersObject = {
835
835
const pass =
836
836
typeof expected === 'string'
837
837
? received . includes ( expected )
838
- : expected . test ( received ) ;
838
+ : new RegExp ( expected ) . test ( received ) ;
839
839
840
840
const message = pass
841
841
? ( ) =>
You can’t perform that action at this time.
0 commit comments