mirror of https://github.com/curbengh/hexo-yam
				
				
				
			test: utilise toThrow() to catch error
- try...catch would (incorrectly) pass the test, despite having no error
This commit is contained in:
		
							parent
							
								
									b9f4cd6173
								
							
						
					
					
						commit
						81ab472fe1
					
				|  | @ -65,20 +65,15 @@ describe('css', () => { | |||
|     } | ||||
|     hexo.config.minify.css = customOpt | ||||
| 
 | ||||
|     let result, expected | ||||
| 
 | ||||
|     try { | ||||
|       await c(input, { path }) | ||||
|     } catch (err) { | ||||
|       result = err.message | ||||
|     } | ||||
|     let expected | ||||
|     try { | ||||
|       await new CleanCSS(customOpt).minify(input) | ||||
|     } catch (err) { | ||||
|       expected = err.message | ||||
|     } | ||||
| 
 | ||||
|     expect(result).toContain(expected) | ||||
|     expect(expected).toBeDefined() | ||||
|     await expect(c(input, { path })).rejects.toThrow(expected) | ||||
|   }) | ||||
| 
 | ||||
|   test('exclude - *.min.css', async () => { | ||||
|  |  | |||
|  | @ -99,11 +99,8 @@ describe('gzip', () => { | |||
|     } catch (err) { | ||||
|       expected = err.message | ||||
|     } | ||||
|     try { | ||||
|       await g() | ||||
|     } catch (err) { | ||||
|       expect(err.message).toContain(expected) | ||||
|     } | ||||
|     expect(expected).toBeDefined() | ||||
|     await expect(g()).rejects.toThrow(expected) | ||||
|   }) | ||||
| 
 | ||||
|   test('include - exclude non-text file by default', async () => { | ||||
|  |  | |||
|  | @ -69,11 +69,11 @@ describe('js', () => { | |||
|     hexo.config.minify.js = customOpt | ||||
| 
 | ||||
|     const { error } = Terser.minify(input, customOpt) | ||||
|     try { | ||||
| 
 | ||||
|     expect(error.message).toBeDefined() | ||||
|     expect(() => { | ||||
|       j(input, { path }) | ||||
|     } catch (err) { | ||||
|       expect(err.message).toContain(error.message) | ||||
|     } | ||||
|     }).toThrow(error.message) | ||||
|   }) | ||||
| 
 | ||||
|   test('exclude - *.min.js', () => { | ||||
|  |  | |||
|  | @ -51,11 +51,7 @@ describe('xml', () => { | |||
| 
 | ||||
|   test('invalid input', async () => { | ||||
|     hexo.route.set(path, 'foo') | ||||
|     try { | ||||
|       await jsonFn() | ||||
|     } catch (err) { | ||||
|       expect(err.message).toContain('SyntaxError') | ||||
|     } | ||||
|     await expect(jsonFn()).rejects.toThrow(/SyntaxError/) | ||||
|   }) | ||||
| 
 | ||||
|   test('empty file', async () => { | ||||
|  |  | |||
|  | @ -81,11 +81,8 @@ describe('svg', () => { | |||
|     } catch (err) { | ||||
|       expected = err | ||||
|     } | ||||
|     try { | ||||
|       await s() | ||||
|     } catch (err) { | ||||
|       expect(err.message).toContain(expected) | ||||
|     } | ||||
|     expect(expected).toBeDefined() | ||||
|     await expect(s()).rejects.toThrow(expected) | ||||
|   }) | ||||
| 
 | ||||
|   test('include - exclude *.min.svg by default', async () => { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue