add some unit tests and a gitlab ci

This commit is contained in:
lukas 2020-06-09 17:49:41 +02:00
parent 46be02f912
commit c5f0788180
3 changed files with 37 additions and 1 deletions

20
.gitlab-ci.yml Normal file
View 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

View File

@ -13,7 +13,7 @@ class Tag extends React.Component {
render() {
// todo onclick events correctlyy
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
View 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");
});