add some unit tests and a gitlab ci
This commit is contained in:
		
							
								
								
									
										20
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					image: node:latest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					stages:
 | 
				
			||||||
 | 
					  - test
 | 
				
			||||||
 | 
					  - build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cache:
 | 
				
			||||||
 | 
					  paths:
 | 
				
			||||||
 | 
					    - node_modules/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test:
 | 
				
			||||||
 | 
					  stage: test
 | 
				
			||||||
 | 
					  script:
 | 
				
			||||||
 | 
					    - npm install
 | 
				
			||||||
 | 
					    - npm run test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					build:
 | 
				
			||||||
 | 
					  stage: build
 | 
				
			||||||
 | 
					  script:
 | 
				
			||||||
 | 
					    - npm run build
 | 
				
			||||||
@@ -13,7 +13,7 @@ class Tag extends React.Component {
 | 
				
			|||||||
    render() {
 | 
					    render() {
 | 
				
			||||||
        // todo onclick events correctlyy
 | 
					        // todo onclick events correctlyy
 | 
				
			||||||
        return (
 | 
					        return (
 | 
				
			||||||
            <button className='tagbtn' onClick={this.props.onClick}>{this.props.children}</button>
 | 
					            <button className='tagbtn' onClick={this.props.onClick} data-testid="Test-Tag">{this.props.children}</button>
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										16
									
								
								src/elements/Tag.test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/elements/Tag.test.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					import React from "react";
 | 
				
			||||||
 | 
					import ReactDom from 'react-dom'
 | 
				
			||||||
 | 
					import Tag from './Tag'
 | 
				
			||||||
 | 
					import {render} from '@testing-library/react'
 | 
				
			||||||
 | 
					import "@testing-library/jest-dom"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					it('renders without crashing ', function () {
 | 
				
			||||||
 | 
					    const div = document.createElement("div");
 | 
				
			||||||
 | 
					    ReactDom.render(<Tag/>,div);
 | 
				
			||||||
 | 
					    ReactDom.unmountComponentAtNode(div);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					it('renders childs correctly', function () {
 | 
				
			||||||
 | 
					    const {getByTestId} = render(<Tag>test</Tag>);
 | 
				
			||||||
 | 
					    expect(getByTestId("Test-Tag")).toHaveTextContent("test");
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
		Reference in New Issue
	
	Block a user