@@ -84,22 +84,29 @@ module.exports = function (src, filePath, jestConfig) {
8484 }
8585
8686 if ( Array . isArray ( parts . styles ) && parts . styles . length > 0 ) {
87- if ( ( parts . styles . some ( ast => / ^ s c s s | s a s s | l e s s | p c s s | p o s t c s s / . test ( ast . lang ) ) ) && logger . shouldLogStyleWarn ) {
87+ if ( ( parts . styles . some ( ast => / ^ s a s s | l e s s | p c s s | p o s t c s s / . test ( ast . lang ) ) ) && logger . shouldLogStyleWarn ) {
8888 ! config . hideStyleWarn && logger . warn ( 'Sass, Less and PostCSS are not currently compiled by vue-jest' )
8989 logger . shouldLogStyleWarn = false
9090 }
9191
92- const styleStr = parts . styles . map ( ast => {
93- if ( ! module ) return
94-
95- const styleObj = ( / ^ s a s s | l e s s | p c s s | p o s t c s s / . test ( ast . lang ) )
96- ? { }
97- : processStyle ( ast , filePath , config )
98-
99- const moduleName = ast . module === true ? '$style' : ast . module
100-
101- return '\n this[\'' + moduleName + '\'] = ' + JSON . stringify ( styleObj )
102- } ) . filter ( _ => _ )
92+ const styleStr = parts . styles
93+ . filter ( ast => module && ast . module )
94+ . map ( ast => {
95+ const styleObj = ( / ^ s a s s | l e s s | p c s s | p o s t c s s / . test ( ast . lang ) )
96+ ? { }
97+ : processStyle ( ast , filePath , config )
98+
99+ const moduleName = ast . module === true ? '$style' : ast . module
100+
101+ return `
102+ if(!this['${ moduleName } ']) {
103+ this['${ moduleName } '] = {};
104+ }
105+ this['${ moduleName } '] = Object.assign(this['${ moduleName } '], ${ JSON . stringify ( styleObj ) } );
106+ `
107+ } )
108+ . filter ( _ => _ )
109+ . join ( '' )
103110
104111 if ( styleStr . length !== 0 ) {
105112 output += '\n;(function() {' +
0 commit comments