File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed
Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 44
55### Fixes
66
7+ - ` [jest-mock] ` Treat cjs modules as objects so they can be mocked ([ #13513 ] ( https://github.com/facebook/jest/pull/13513 ) )
8+
79### Chore & Maintenance
810
911- ` [@jest/transform] ` Update ` convert-source-map ` ([ #13509 ] ( https://github.com/facebook/jest/pull/13509 ) )
Original file line number Diff line number Diff line change @@ -213,6 +213,20 @@ describe('moduleMocker', () => {
213213 expect ( mock . enumGetter ) . toBeDefined ( ) ;
214214 } ) ;
215215
216+ it ( 'handles custom toString of transpiled modules' , ( ) => {
217+ const foo = Object . defineProperties (
218+ { foo : 'bar' } ,
219+ {
220+ __esModule : { value : true } ,
221+ [ Symbol . toStringTag ] : { value : 'Module' } ,
222+ } ,
223+ ) ;
224+ const mock = moduleMocker . generateFromMetadata (
225+ moduleMocker . getMetadata ( foo ) ,
226+ ) ;
227+ expect ( mock . foo ) . toBeDefined ( ) ;
228+ } ) ;
229+
216230 it ( 'mocks ES2015 non-enumerable methods' , ( ) => {
217231 class ClassFoo {
218232 foo ( ) { }
Original file line number Diff line number Diff line change @@ -426,7 +426,7 @@ function getType(ref?: unknown): MockMetadataType | null {
426426 return 'function' ;
427427 } else if ( Array . isArray ( ref ) ) {
428428 return 'array' ;
429- } else if ( typeName === 'Object' ) {
429+ } else if ( typeName === 'Object' || typeName === 'Module' ) {
430430 return 'object' ;
431431 } else if (
432432 typeName === 'Number' ||
You can’t perform that action at this time.
0 commit comments