| 
									
										
										
										
											2017-02-18 04:05:12 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 04:05:12 +08:00
										 |  |  | const path = require("path"); | 
					
						
							|  |  |  | const ModuleDependencyError = require("../lib/ModuleDependencyError"); | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 04:05:12 +08:00
										 |  |  | describe("ModuleDependencyError", () => { | 
					
						
							|  |  |  | 	let env; | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	beforeEach(() => { | 
					
						
							|  |  |  | 		env = {}; | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 04:05:12 +08:00
										 |  |  | 	describe("when new error created", () => { | 
					
						
							|  |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 			env.error = new Error("Error Message"); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 			env.moduleDependencyError = new ModuleDependencyError( | 
					
						
							|  |  |  | 				"myModule", | 
					
						
							|  |  |  | 				env.error, | 
					
						
							|  |  |  | 				"Location" | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("is an error", () => { | 
					
						
							|  |  |  | 			expect(env.moduleDependencyError).toBeInstanceOf(Error); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("has a name property", () => { | 
					
						
							|  |  |  | 			expect(env.moduleDependencyError.name).toBe("ModuleDependencyError"); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("has a message property", () => { | 
					
						
							|  |  |  | 			expect(env.moduleDependencyError.message).toBe("Location Error Message"); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("has a details property", () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 			expect(env.moduleDependencyError.details).toMatch( | 
					
						
							|  |  |  | 				path.join("test", "ModuleDependencyError.unittest.js:") | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("has an origin property", () => { | 
					
						
							|  |  |  | 			expect(env.moduleDependencyError.origin).toBe("myModule"); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("has an error property", () => { | 
					
						
							|  |  |  | 			expect(env.moduleDependencyError.error).toBe(env.error); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-17 06:00:49 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }); |