Add Jest-Serializer-Vue-TJW
This commit is contained in:
		
							parent
							
								
									3db2da197c
								
							
						
					
					
						commit
						446b730430
					
				| @ -21,7 +21,7 @@ module.exports = { | |||||||
|     '<rootDir>/tests/unit/setup.js' |     '<rootDir>/tests/unit/setup.js' | ||||||
|   ], |   ], | ||||||
|   snapshotSerializers: [ |   snapshotSerializers: [ | ||||||
|     '<rootDir>/tests/unit/serializer.js' |     '<rootDir>/node_modules/jest-serializer-vue-tjw' | ||||||
|   ], |   ], | ||||||
|   testEnvironment: 'jest-environment-jsdom-global', |   testEnvironment: 'jest-environment-jsdom-global', | ||||||
|   testMatch: [ |   testMatch: [ | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										10
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -15616,6 +15616,16 @@ | |||||||
|         "pretty": "2.0.0" |         "pretty": "2.0.0" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|  |     "jest-serializer-vue-tjw": { | ||||||
|  |       "version": "3.3.0", | ||||||
|  |       "resolved": "https://registry.npmjs.org/jest-serializer-vue-tjw/-/jest-serializer-vue-tjw-3.3.0.tgz", | ||||||
|  |       "integrity": "sha512-pvUqkwTYqmlHRuE6KtzNitBD5LRuuXgBt83cfSMabM9+QJEetm87nhIIAi4drDZeSOdkuVthBrcWE5E9AfUokw==", | ||||||
|  |       "dev": true, | ||||||
|  |       "requires": { | ||||||
|  |         "lodash.clonedeep": "^4.5.0", | ||||||
|  |         "pretty": "^2.0.0" | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|     "jest-transform-stub": { |     "jest-transform-stub": { | ||||||
|       "version": "2.0.0", |       "version": "2.0.0", | ||||||
|       "resolved": "https://registry.npmjs.org/jest-transform-stub/-/jest-transform-stub-2.0.0.tgz", |       "resolved": "https://registry.npmjs.org/jest-transform-stub/-/jest-transform-stub-2.0.0.tgz", | ||||||
|  | |||||||
| @ -69,6 +69,7 @@ | |||||||
|     "jest": "^24.9.0", |     "jest": "^24.9.0", | ||||||
|     "jest-environment-jsdom": "^24.9.0", |     "jest-environment-jsdom": "^24.9.0", | ||||||
|     "jest-environment-jsdom-global": "^1.2.0", |     "jest-environment-jsdom-global": "^1.2.0", | ||||||
|  |     "jest-serializer-vue-tjw": "^3.3.0", | ||||||
|     "jest-transform-stub": "^2.0.0", |     "jest-transform-stub": "^2.0.0", | ||||||
|     "nw": "0.43.6-sdk", |     "nw": "0.43.6-sdk", | ||||||
|     "nw-vue-devtools-prebuilt": "^0.0.10", |     "nw-vue-devtools-prebuilt": "^0.0.10", | ||||||
|  | |||||||
| @ -1,42 +0,0 @@ | |||||||
| // Based on jest-serializer-vue
 |  | ||||||
| 
 |  | ||||||
| const beautify = require('pretty'); |  | ||||||
| 
 |  | ||||||
| function isHtmlString (received) { |  | ||||||
|   return received && typeof(received) === 'string' && received.startsWith('<'); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function isVueWrapper (received) { |  | ||||||
|   return received && typeof(received) === 'object' && typeof(received.isVueInstance) === 'function'; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // This removes data-test="whatever" from your snapshots
 |  | ||||||
| // If you also want to remove them from your production builds, see:
 |  | ||||||
| // https://forum.vuejs.org/t/how-to-remove-attributes-from-tags-inside-vue-components/24138
 |  | ||||||
| function removeDataTestAttributes (html) { |  | ||||||
|   // [-\w]+ will catch 1 or more instaces of a-z, A-Z, 0-9, hyphen (-), or underscore (_)
 |  | ||||||
|   return html.replace(/ data-test="[-\w]+"/g, ''); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| module.exports = { |  | ||||||
|   test: function (received) { |  | ||||||
|     return isHtmlString(received) || isVueWrapper(received); |  | ||||||
|   }, |  | ||||||
|   print: function (received) { |  | ||||||
|     let html = received || ''; |  | ||||||
|     if (isVueWrapper(received)) { |  | ||||||
|       html = received.html(); |  | ||||||
|     } |  | ||||||
|     html = removeDataTestAttributes(html); |  | ||||||
|     // To see available options: https://github.com/beautify-web/js-beautify/blob/master/js/src/html/options.js
 |  | ||||||
|     const options = { |  | ||||||
|       indent_size: 2, |  | ||||||
|       unformatted: ['code', 'pre'], |  | ||||||
|       inline: [], |  | ||||||
|       indent_inner_html: true, |  | ||||||
|       indent_char: ' ', |  | ||||||
|       sep: '\n' |  | ||||||
|     }; |  | ||||||
|     return beautify(html, options); |  | ||||||
|   } |  | ||||||
| }; |  | ||||||
| @ -22,6 +22,7 @@ window.getComputedStyle = function getComputedStyleStub (el) { | |||||||
| 
 | 
 | ||||||
| global.beforeEach(() => { | global.beforeEach(() => { | ||||||
|   window.process = { |   window.process = { | ||||||
|  |     cwd: process.cwd, | ||||||
|     env: { |     env: { | ||||||
|       NODE_ENV: 'development' |       NODE_ENV: 'development' | ||||||
|     }, |     }, | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user