2022-03-15 13:47:42 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# Component testing with Playwright and Vue3
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Recommended IDE Setup
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[VSCode ](https://code.visualstudio.com/ ) + [Volar ](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar ) (and disable Vetur) + [TypeScript Vue Plugin (Volar) ](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.vscode-typescript-vue-plugin ) + [Playwright Test for VSCode ](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Project Setup
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```sh
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								npm i
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Compile and Hot-Reload for Development
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```sh
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								npm run dev
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Test project
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Run tests from your VS Code, or execute
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```sh
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								npm run test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## How to add component tests using Playwright
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  npm init vue@latest  was used to create a default project. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ```sh
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    npm init vue@latest 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 18:00:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  Install Playwright Test with component testing as dev dependencies. 
						 
					
						
							
								
									
										
										
										
											2022-03-15 13:47:42 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ```sh
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    npm i --save-dev @playwright/test  @playwright/experimental -ct-vue
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-04 15:01:48 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  [playwright/index.html ](playwright/index.html ) file was added that defines theming for the components through importing [playwright/index.js ](playwright/index.js ). 
						 
					
						
							
								
									
										
										
										
											2022-05-02 18:00:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-04 15:01:48 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  [playwright.config.ts ](playwright.config.ts ) was added that builds components before running tests. 
						 
					
						
							
								
									
										
										
										
											2022-05-02 18:00:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2022-03-15 13:47:42 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								-  A bunch of `.spec.ts`  and `.spec.tsx`  files were added to `src`  that demonstrate Vue3 component testing with and without the use of JSX syntax.