2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								include ../_util-fns
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								  We’ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  We’ 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  我们将使用[Jasmine测试框架](http://jasmine.github.io/2.3/introduction.html)编写我们的测试。
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  我们以把*一些*测试弄成功为开始。
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  We will learn  
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - basic Jasmine testing skills
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - to run our tests in the browser
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - to write simple Jasmine tests in TypeScript
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - to debug a test in the browser
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  我们会学到:  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - 基础Jasmine测试技能
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - 在浏览器里面运行我们的测试
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - 使用TypeScript编写简单的Jasmine测试
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - 在浏览器里调试一个测试
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  **Create a new project folder** perhaps called `angular2-unit-testing`.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  **新建一个项目目录**,起名为`angular2-unit-testing`。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Install npm packages locally
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  ## 本地安装npm包
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  Next follow all of  the steps prescribed in  “Install npm packages locally” of the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  [QuickStart](../quickstart.html).
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  下一步,完成[快速开始](../quickstart.html)中的“本地安装npm包”的每一步。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  We’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  然后我们通过npm添加Jasmine包: 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								pre.prettyprint.lang-bash
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								   code npm install jasmine-core --save-dev --save-exact
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.alert.is-important
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Be sure to install `jasmine-core` , not `jasmine`!
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								    确认安装的是`jasmine-core`,不是`jasmine`! 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  **Create a sub-folder `src` ** for our tests and then **cd into it**.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  为我们的测试**新建一个子目录`src`**,然后**cd到里面**。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  We are going to **display and control our tests in the browser**.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  我们将会**在浏览器里面显示和控制我们的测试**。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								    The browser is nice during development of a few tests. It’ ’ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								    We’ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    在我们开发一些测试的过程中,浏览器很有帮助。它却并不是最好的开发很多测试的地方,它更不能用来做建构自动化。
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    到时我们将会切换到Karma测试运行器。但是现在先用浏览器。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  Create a new file called`unit-tests.html` and enter the following:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  新建一个文件叫做`unit-tests.html`,并把下面的内容输入进去:
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								+makeExample('testing/ts/unit-tests-0.html', 'no-script', 'unit-tests.html')
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  In the head we have three Jasmine scripts and one Jasmine css file. That’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-05-09 21:50:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								  在head里面, 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  We’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  我们接下来以内嵌JavaScript的形式在body表示里面, : 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								+makeExample('testing/ts/unit-tests-0.html', 'body')(format='.')
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-04 17:56:41 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  Now open `unit-tests.html` in a browser and see the Jasmine HTML test output:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  现在,在浏览器里打开`unit-tests.html`, : 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								figure.image-display
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    img(src='/resources/images/devguide/jasmine-testing-101/jasmine-1-spec-0-failures.png' style="height:170px;" alt="Jasmine HTML test output")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  It doesn’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  这个已经是简单的不能再简单了。
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 01:06:56 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## First TypeScript Test
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  ## 第一个TypeScript测试
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								  Perhaps too simple. We won’ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  Let’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  或许过于简单。我们不会再一个HTML文件里面编写整套测试。让我们把这行测试代码**提取**到**`src`目录下的新文件`1st.spec.ts`**。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								.l-sub-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								    Among Jasmine developers, a test is known as a “spec” and test filenames include the word “spec”.  We’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								    在Jasmine开发者中, , 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  The test we wrote is valid TypeScript because any JavaScript is valid TypeScript. But let’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								  我们编写的测试是一个有效的TypeScript, : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								+makeExample('testing/ts/1st.spec.ts', 'it', '1st.spec.ts')
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-04 17:56:41 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  Now modify `unit-tests.html` to load the script:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  现在修改`unit-tests.html`来加载上面的脚本:
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								+makeExample('testing/ts/unit-tests-1.html', 'script')
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-04 17:56:41 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								  Hold on! We wrote a TypeScript file but we’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  等等! , ? 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  That’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  这是一个提醒, , 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 01:06:56 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Prepare for TypeScript
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  ## 为TypeScript做准备
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								  As we’ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  a ** `tsconfig.json` **.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  和我们见过的一样,我们必须通过*`tsconfig.json`*, 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  We can copy one from the quickstart we wrote previously and paste it into our src sub-folder.
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  It should look something like this:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  我们可以从快速开始拷贝一个之前已写好的, , : 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								+makeExample('testing/ts/tsconfig.1.json', null, 'tsconfig.json')
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Compile and Run
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  ## 编译和运行
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  Compile in the terminal window using the npm script command
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  在终端窗口, : 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								pre.prettyprint.lang-bash
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  code npm run tsc
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								.alert.is-helpful
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								    Our editor and the compiler may complain that they don’ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    what `it` and `expect` are because they lack the typing files that describe Jasmine.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    We can ignore those annoying complaints for now as they are harmless.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2016-05-09 21:50:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								    我们的编辑器和编译器可能会抱怨,说它们不知道什么是`it`和`expect`, , 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  If we reload the browser, we should see the same Jasmine test-runner output as before.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  如果我们刷新浏览器, 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								  We’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  我们可以迅速进化这些测试,让浏览器在我们做出修改和重新编译时自动刷新的话就更方便了。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  Let’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  让我们在另一个终端窗口启动一个**live-server**。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								pre.prettyprint.lang-bash
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  code npm start
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2016-04-02 20:14:34 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  Now reload `unit-tests.html` in the browser
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  现在在浏览器刷新`unit-tests.html`
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  We should get the same Jasmine test-runner output as before.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-19 16:07:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  我们应该能看到一样的Jasmine测试运行器输出。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 01:06:56 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Add a describe and another test
							 
						 
					
						
							
								
									
										
										
										
											2016-05-09 21:50:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  ## 添加一个describe和其它测试
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  We can’ ’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  我们不知道什么文件生成了这些测试结果。虽然我们目前只有一个文件但是我们会编写更多。
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  We should wrap this test into something that identifies the file. In Jasmine that “something” is a `describe` function.  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  Every test file should have at least one `describe` that identifies the file holding the test(s).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  我们应该把这个测试包裹到一个可以识别这个文件的东西。在Jasmine里, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  每个测试文件都应该至少有一个`describe`来标识这个文件测试了什么。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 20:25:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								  Here’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  下面是我们修改`1st.spec.ts`,用`describe`包裹后的结果:
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								+makeExample('testing/ts/1st.spec.ts', 'describe')
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  And here’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  下面是测试报告的显示:
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								figure.image-display
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    img(src='/resources/images/devguide/jasmine-testing-101/test-report-1-spec-0-failures.png' style="height:100px;" alt="1 spec, 0 failures")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  Let’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  让我们添加另一个测试到`1st.spec.ts`
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 14:07:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								+makeExample('testing/ts/1st.spec.ts', 'another-test')(format=".")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-04 17:56:41 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  You knew that right?  Let’ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  你知道这个吧?让我们用这个测试来证明。浏览器应该在你粘贴那个测试后更新,然后显示:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								figure.image-display
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    img(src='/resources/images/devguide/jasmine-testing-101/test-report-2-specs-0-failures.png' style="height:100px;" alt="refreshed 2 specs, 0 failures")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  What does a failing test look like? Remove the `.not`. The browser refreshes and shows:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  测试失败是什么样子?删除`.net`,刷新浏览器:
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								figure.image-display
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    img(src='/resources/images/devguide/jasmine-testing-101/test-report-2-specs-1-failure.png' style="height:190px;" alt="failing test 2 specs, 1 failure")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  Click the `Spec List` link just below “2 specs, 1 failure” to see the summary again:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  点击“2 Specs, 1 failure”下面的`Spec List`链接,看看总结:
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								figure.image-display
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    img(src='/resources/images/devguide/jasmine-testing-101/spec-list-2-specs-1-failure.png' style="height:140px;" alt="2 specs, 1 failure")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  We can re-run just the failing test by double-clicking it.  Try it!
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  我们可以只重新运行失败的测试,点击它就可以了。试试!
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-16 01:06:56 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								.l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  ## Debug the test
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  ## 调试测试
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  Suppose we didn’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  假设我们不知道是怎么回事。我们都能在浏览器里面调试它。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								    - Open the browser’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								    - 打开浏览器的“开发者工具”( 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - Pick the “sources” section
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    - 选择"sources"标签
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - Open the `1st.spec.ts` test file (Ctrl-P, then start typing the name of the file).
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								    - 打开`1st.spec.ts`测试文件( 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - Set a breakpoint on the second line of the failing test
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    - 在失败的测试的第二行,设置一个断点
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - Refresh the browser … and it stops at our breakpoint.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    - 刷新浏览器...然后它停在我们的断点上
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - Open the console window at the bottom  (press Esc)
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								    - 在底部打开console窗口( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - Type `null === undefined` … … and we should see this:
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    - 输入`null === undefined`...然后我们可以看到这个:
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								figure.image-display
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    img(src='/resources/images/devguide/jasmine-testing-101/null-to-equal-undefined.png' style="height:500px;" alt="null === undefined")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								:marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  How about that!  They really aren’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  你觉得怎么样?它们真的不相等。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - remove the breakpoint (right-click in the “Breakpoints” section and chose “Remove breakpoint”)
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								    - 移除断点( , 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    - Click the “play” icon to resume the test  (or F8)
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								    - 点击“play”图标来继续运行测试( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  And the test finishes.  Close the browser tools (click the close box or press F12 or Ctrl-Shift-I)
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  然后测试完成。关闭浏览器工具( 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  Fix the test (restore the `.not`);  the browser should refresh automatically and all tests pass.
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  修复测试(恢复`.not`);浏览器应该自动刷新,所有测试都通过。
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  Congratulations … you’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  恭喜...你完成了Jasmine测试101。
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2016-02-05 23:27:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								  Now that we’ ’ 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-22 10:54:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								  现在, , 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-09 10:33:12 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-17 10:01:41 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  <!-- TODO
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  .l-main-section
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 18:31:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  :marked
							 
						 
					
						
							
								
									
										
										
										
											2015-10-17 10:01:41 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    ## Learn more
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    Learn more about basic Jasmine testing here
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    [Resources TBD](./#)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    -->