Add test case for error stringifier
This commit is contained in:
		
							parent
							
								
									741311a9b7
								
							
						
					
					
						commit
						c1592fcb95
					
				
					 1 changed files with 23 additions and 0 deletions
				
			
		
							
								
								
									
										23
									
								
								src/m2d/event-dispatcher.test.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/m2d/event-dispatcher.test.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | |||
| // @ts-check
 | ||||
| 
 | ||||
| const {test} = require("supertape") | ||||
| const {stringifyErrorStack} = require("./event-dispatcher") | ||||
| 
 | ||||
| test("stringify error stack: works", t => { | ||||
| 	function a() { | ||||
| 		const e = new Error("message", {cause: new Error("inner")}) | ||||
| 		// @ts-ignore
 | ||||
| 		e.prop = 2.1 | ||||
| 		throw e | ||||
| 	} | ||||
| 	try { | ||||
| 		a() | ||||
| 		t.fail("shouldn't get here") | ||||
| 	} catch (e) { | ||||
| 		const str = stringifyErrorStack(e) | ||||
| 		t.match(str, /^Error: message$/m) | ||||
| 		t.match(str, /^    at a \(.*event-dispatcher\.test\.js/m) | ||||
| 		t.match(str, /^  \[cause\]: Error: inner$/m) | ||||
| 		t.match(str, /^  \[prop\]: 2.1$/m) | ||||
| 	} | ||||
| }) | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue