Skip to content

Commit

Permalink
add Button tests
Browse files Browse the repository at this point in the history
  • Loading branch information
estevanmaito committed May 17, 2019
1 parent fa74a3e commit 0bde25c
Show file tree
Hide file tree
Showing 7 changed files with 713 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
coverage/
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@babel/preset-env']
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
},
"homepage": "https://github.com/estevanmaito/sharect#readme",
"scripts": {
"test": "jest",
"test": "jest --watch",
"test:coverage": "jest --coverage",
"build": "webpack",
"dev": "webpack --watch"
},
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"babel-loader": "^8.0.6",
"jest": "^24.7.1",
"webpack": "^4.31.0",
"webpack-cli": "^3.3.2",
Expand Down
47 changes: 46 additions & 1 deletion src/__tests__/Button/Button.test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
import Button from '../Button/Button'
import Button from '../../Button/Button'
import style from '../../Button/style'

describe('Button', () => {
it('should render a button element', () => {
const button = Button('icon')
expect(button).toMatchSnapshot()
})

it('should call handleMouseDown on mousedown', () => {
const handleMouseDown = jest.fn()
const button = Button('icon', handleMouseDown)
button.onmousedown()

expect(handleMouseDown).toHaveBeenCalled()
})

it('should contain an icon in innerHTML', () => {
const button = Button('icon')

expect(button.innerHTML).toBe('icon')
})

it('should have style', () => {
const button = Button('icon')

const styledButton = document.createElement('div')
styledButton.style.cssText = style

expect(button.style.cssText).toEqual(styledButton.style.cssText)
})

it('should grow transform scale on mouseover', () => {
const button = Button('icon')
button.onmouseover()

expect(button.style.transform).toEqual("scale(1.2)")
})

it('should return to the initial transform scale on mouseout', () => {
const button = Button('icon')
button.onmouseout()

expect(button.style.transform).toEqual("scale(1)")
})

})
9 changes: 9 additions & 0 deletions src/__tests__/Button/__snapshots__/Button.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Button should render a button element 1`] = `
<div
style="display: inline-block; margin: 7px; cursor: pointer; transition: all .2s ease-in-out;"
>
icon
</div>
`;
14 changes: 14 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,19 @@ module.exports = {
filename: "sharect.js",
library: "Sharect",
libraryTarget: "umd"
},
module: {
rules: [
{
test: /\.js$/,
excludes: /(node_modules|docs)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
};
Loading

0 comments on commit 0bde25c

Please sign in to comment.