| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Extra Mocha-specific typings to make sure typescript compiler is happy
 | 
					
						
							|  |  |  | // Didn't want to add @types/mocha because of duplication in typings-file with @types/jasmine
 | 
					
						
							|  |  |  | declare function suite(description: string, suiteFn: () => void): void; | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  | declare function test(description: string, testFn: () => void): void; | 
					
						
							|  |  |  | declare function specify(description: string, testFn: () => void): void; | 
					
						
							|  |  |  | declare function setup(fn: () => void): void; | 
					
						
							|  |  |  | declare function teardown(fn: () => void): void; | 
					
						
							|  |  |  | declare function suiteSetup(fn: () => void): void; | 
					
						
							|  |  |  | declare function suiteTeardown(fn: () => void): void; | 
					
						
							|  |  |  | declare function before(fn: () => void): void; | 
					
						
							|  |  |  | declare function after(fn: () => void): void; | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {ifEnvSupports} from './test-util'; | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | ifEnvSupports('Mocha', function() { | 
					
						
							|  |  |  |   describe('Mocha BDD-style', () => { | 
					
						
							|  |  |  |     let throwOnAsync = false; | 
					
						
							|  |  |  |     let beforeEachZone: Zone|null = null; | 
					
						
							|  |  |  |     let itZone: Zone|null = null; | 
					
						
							|  |  |  |     const syncZone = Zone.current; | 
					
						
							|  |  |  |     let beforeZone: Zone|null = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |     before(() => { | 
					
						
							|  |  |  |       beforeZone = Zone.current; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       Zone.current.scheduleMicroTask('dontallow', (): any => null); | 
					
						
							|  |  |  |     } catch (e) { | 
					
						
							|  |  |  |       throwOnAsync = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     beforeEach(() => beforeEachZone = Zone.current); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should throw on async in describe', () => { | 
					
						
							|  |  |  |       expect(Zone.currentTask).toBeTruthy(); | 
					
						
							|  |  |  |       expect(throwOnAsync).toBe(true); | 
					
						
							|  |  |  |       expect(syncZone.name).toEqual('syncTestZone for Mocha.describe'); | 
					
						
							|  |  |  |       itZone = Zone.current; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     afterEach(() => { | 
					
						
							|  |  |  |       let zone = Zone.current; | 
					
						
							|  |  |  |       expect(zone.name).toEqual('ProxyZone'); | 
					
						
							|  |  |  |       expect(beforeEachZone).toBe(zone); | 
					
						
							|  |  |  |       expect(itZone).toBe(zone); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |     after(() => { | 
					
						
							|  |  |  |       expect(beforeZone).toBe(Zone.current); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   suite('Mocha TDD-style', () => { | 
					
						
							|  |  |  |     let testZone: Zone|null = null; | 
					
						
							|  |  |  |     let beforeEachZone: Zone|null = null; | 
					
						
							|  |  |  |     let suiteSetupZone: Zone|null = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |     suiteSetup(() => { | 
					
						
							|  |  |  |       suiteSetupZone = Zone.current; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |     setup(() => { | 
					
						
							|  |  |  |       beforeEachZone = Zone.current; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     test('should run in Zone with "test"-syntax in TDD-mode', () => { | 
					
						
							|  |  |  |       testZone = Zone.current; | 
					
						
							|  |  |  |       expect(Zone.currentTask).toBeTruthy(); | 
					
						
							|  |  |  |       expect(testZone.name).toEqual('ProxyZone'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     specify('test should run in Zone with "specify"-syntax in TDD-mode', () => { | 
					
						
							|  |  |  |       testZone = Zone.current; | 
					
						
							|  |  |  |       expect(Zone.currentTask).toBeTruthy(); | 
					
						
							|  |  |  |       expect(testZone.name).toEqual('ProxyZone'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     teardown(() => { | 
					
						
							|  |  |  |       expect(Zone.current.name).toEqual('ProxyZone'); | 
					
						
							|  |  |  |       expect(beforeEachZone).toBe(Zone.current); | 
					
						
							|  |  |  |       expect(testZone).toBe(Zone.current); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |     suiteTeardown(() => { | 
					
						
							|  |  |  |       expect(suiteSetupZone).toBe(Zone.current); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('return promise', () => { | 
					
						
							|  |  |  |     let log: string[]; | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |     beforeEach(() => { | 
					
						
							|  |  |  |       log = []; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should wait for promise to resolve', () => { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:58:29 -05:00
										 |  |  |       return new Promise<void>((res, _) => { | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |         setTimeout(() => { | 
					
						
							|  |  |  |           log.push('resolved'); | 
					
						
							|  |  |  |           res(); | 
					
						
							|  |  |  |         }, 100); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |     afterEach(() => { | 
					
						
							|  |  |  |       expect(log).toEqual(['resolved']); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  | })(); |