Skip to content

Commit

Permalink
Upgrade Tests to Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
casesandberg committed Mar 5, 2017
1 parent 970f83f commit e3b817c
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 256 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
module.exports = { extends: '@case/eslint-config' }
module.exports = {
extends: '@case/eslint-config',
env: {
jest: true
}
}
18 changes: 6 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
"scripts": {
"clean": "rm -rf lib && mkdir lib",
"lib": "npm run clean && babel src -d lib",
"test": "npm run unit-test",
"unit-test": "mocha test/** --compilers js:babel-register",
"tdd": "mocha test/** --compilers js:babel-register --watch",
"test": "npm run unit-test -s && npm run eslint -s",
"unit-test": "node_modules/.bin/jest",
"tdd": "node_modules/.bin/jest --watchAll",
"docs": "webpack-dev-server --config webpack.dev.js --port 2570",
"docs-dist": "webpack --config webpack.prod.js",
"dev": "npm run docs",
"prepublish": "npm run lib",
"eslint": "node_modules/.bin/eslint src/**/*.js",
"posttest": "npm run eslint"
"eslint": "node_modules/.bin/eslint src/**/*.js"
},
"repository": {
"type": "git",
Expand All @@ -41,27 +40,22 @@
"babel-preset-react": "^6.1.18",
"babel-preset-stage-0": "^6.1.18",
"babel-register": "^6.9.0",
"chai": "^2.2.0",
"css-loader": "^0.14.5",
"highlight.js": "^8.6.0",
"html-loader": "^0.3.0",
"install": "^0.4.0",
"jest": "^19.0.2",
"jsx-loader": "^0.13.2",
"markdown-loader": "^0.1.2",
"mocha": "^2.2.1",
"mocha-sinon": "^1.1.4",
"normalize.css": "^3.0.3",
"react": "^15.1.0",
"react-addons-test-utils": "^15.1.0",
"react-context": "0.0.3",
"react-dom": "^15.1.0",
"react-hot-loader": "^1.2.5",
"react-test-renderer": "^15.4.2",
"remarkable": "^1.6.0",
"require-dir": "^0.3.0",
"sinon": "^1.15.3",
"sinon-chai": "^2.8.0",
"style-loader": "^0.12.3",
"testdom": "^2.0.0",
"webpack": "^1.8.11",
"webpack-dev-server": "^1.8.2"
}
Expand Down
54 changes: 54 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`reactCSS should return complex css 1`] = `
<div>
<div
className="card"
style={
Object {
"MozBoxShadow": "0 4px 8px rgba(0,0,0,.15)",
"OBoxShadow": "0 4px 8px rgba(0,0,0,.15)",
"WebkitBoxShadow": "0 4px 8px rgba(0,0,0,.15)",
"boxShadow": "0 4px 8px rgba(0,0,0,.15)",
"msBoxShadow": "0 4px 8px rgba(0,0,0,.15)",
}
}
/>
</div>
`;

exports[`reactCSS should return multiple css 1`] = `
<div>
<div
className="title"
style={
Object {
"color": "red",
}
}
/>
<div
className="card"
style={
Object {
"MozBoxShadow": "0 0 2px rgba(0,0,0,.1)",
"OBoxShadow": "0 0 2px rgba(0,0,0,.1)",
"WebkitBoxShadow": "0 0 2px rgba(0,0,0,.1)",
"boxShadow": "0 0 2px rgba(0,0,0,.1)",
"msBoxShadow": "0 0 2px rgba(0,0,0,.1)",
}
}
/>
</div>
`;

exports[`reactCSS should return simple css 1`] = `
<div
className="body"
style={
Object {
"backgroundColor": "#fafafa",
}
}
/>
`;
11 changes: 4 additions & 7 deletions test/autoprefix.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* global describe, it */

import { expect } from './helpers'
import autoprefix from '../src/autoprefix'

describe('Autoprefix', () => {
it('should prefix borderRadius', () => {
test('should prefix borderRadius', () => {
const before = {
box: {
borderRadius: '2px',
Expand All @@ -19,10 +16,10 @@ describe('Autoprefix', () => {
borderRadius: '2px',
},
}
expect(autoprefix(before)).to.eql(after)
expect(autoprefix(before)).toEqual(after)
})

it('should prefix absolute', () => {
test('should prefix absolute', () => {
const before = {
box: {
absolute: '0px 0px 0px 0px',
Expand All @@ -37,6 +34,6 @@ describe('Autoprefix', () => {
left: '0px',
},
}
expect(autoprefix(before)).to.eql(after)
expect(autoprefix(before)).toEqual(after)
})
})
33 changes: 12 additions & 21 deletions test/flattenNames.test.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
/* global describe, it */

import { expect } from './helpers'
import flattenNames from '../src/flattenNames'

describe('Combine', () => {
it('should return basic strings', () => {
test('should return basic strings', () => {
const before = ['foo', 'bar', 'baz']
const after = ['foo', 'bar', 'baz']

expect(flattenNames(before)).to.eql(after)
expect(flattenNames(before)).toEqual(after)
})

it('should flatten arrays', () => {
test('should flatten arrays', () => {
const before = [['foo', 'bar'], [[['baz']]]]
const after = ['foo', 'bar', 'baz']

expect(flattenNames(before)).to.eql(after)
expect(flattenNames(before)).toEqual(after)
})

it('should return key and key-true when value is true', () => {
test('should return key and key-true when value is true', () => {
const before = [{ foo: true }]
const after = ['foo', 'foo-true']

expect(flattenNames(before)).to.eql(after)
expect(flattenNames(before)).toEqual(after)
})

it('should return key-false when value is false', () => {
test('should return key-false when value is false', () => {
const before = [{ foo: false }]
const after = ['foo-false']

expect(flattenNames(before)).to.eql(after)
expect(flattenNames(before)).toEqual(after)
})

it('should return key-value when value is a string', () => {
test('should return key-value when value is a string', () => {
const before = [{ foo: 'bar' }]
const after = ['foo-bar']

expect(flattenNames(before)).to.eql(after)
expect(flattenNames(before)).toEqual(after)
})

it('should return key-value when value is a number', () => {
test('should return key-value when value is a number', () => {
const before = [{ foo: 2 }]
const after = ['foo-2']

expect(flattenNames(before)).to.eql(after)
expect(flattenNames(before)).toEqual(after)
})
})
18 changes: 0 additions & 18 deletions test/helpers/index.js

This file was deleted.

67 changes: 67 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react'
import renderer from 'react-test-renderer'
import reactCSS from '../src'

describe('reactCSS', () => {
test('should return simple css', () => {
const Component = () => {
const styles = reactCSS({
'default': {
body: {
backgroundColor: '#fafafa',
},
},
})
return <div className="body" style={ styles.body } />
}
const tree = renderer.create(<Component />).toJSON()
expect(tree).toMatchSnapshot()
})

test('should return multiple css', () => {
const Component = ({ color }) => {
const styles = reactCSS({
'default': {
title: {
color,
},
card: {
boxShadow: '0 0 2px rgba(0,0,0,.1)',
},
},
})
return (
<div>
<div className="title" style={ styles.title } />
<div className="card" style={ styles.card } />
</div>
)
}
const tree = renderer.create(<Component color="red" />).toJSON()
expect(tree).toMatchSnapshot()
})

test('should return complex css', () => {
const Component = ({ zIndex }) => {
const styles = reactCSS({
'default': {
card: {
boxShadow: '0 0 2px rgba(0,0,0,.1)',
},
},
'zIndex-2': {
card: {
boxShadow: '0 4px 8px rgba(0,0,0,.15)',
},
},
}, { zIndex })
return (
<div>
<div className="card" style={ styles.card } />
</div>
)
}
const tree = renderer.create(<Component zIndex="2" />).toJSON()
expect(tree).toMatchSnapshot()
})
})
33 changes: 13 additions & 20 deletions test/loop.test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
/* global describe, it */
/* eslint react/prefer-stateless-function: 0 */

import { React, TestUtils, expect } from './helpers'
import React from 'react'
import loopable from '../src/loop'

describe('Loopable', () => {
it('should return first-child if first', () => {
expect(loopable(0, 4)).to.eql({ 'first-child': true, 'nth-child': 0, 'even': true })
test('should return first-child if first', () => {
expect(loopable(0, 4)).toEqual({ 'first-child': true, 'nth-child': 0, 'even': true })
})

it('should return last-child if last', () => {
expect(loopable(3, 4)).to.eql({ 'last-child': true, 'nth-child': 3, 'odd': true })
test('should return last-child if last', () => {
expect(loopable(3, 4)).toEqual({ 'last-child': true, 'nth-child': 3, 'odd': true })
})

it('should return even if even', () => {
expect(loopable(2, 4)).to.eql({ 'even': true, 'nth-child': 2 })
test('should return even if even', () => {
expect(loopable(2, 4)).toEqual({ 'even': true, 'nth-child': 2 })
})

it('should return odd if odd', () => {
expect(loopable(1, 4)).to.eql({ 'odd': true, 'nth-child': 1 })
test('should return odd if odd', () => {
expect(loopable(1, 4)).toEqual({ 'odd': true, 'nth-child': 1 })
})

it('should return simple css', () => {
class Component extends React.Component {
render() {
return <div className="body" />
}
}
const component = TestUtils.renderIntoDocument(<Component { ...loopable(3, 4) } />)
expect(component.props).to.eql({ 'last-child': true, 'nth-child': 3, 'odd': true })
test('should return simple css', () => {
const Component = () => <div className="body" />
const rendered = <Component { ...loopable(3, 4) } />
expect(rendered.props).toEqual({ 'last-child': true, 'nth-child': 3, 'odd': true })
})
})
21 changes: 6 additions & 15 deletions test/mergeClasses.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* global describe, it */

import { expect } from './helpers'
import mergeClasses from '../src/mergeClasses'

describe('Combine', () => {
Expand All @@ -17,8 +14,7 @@ describe('Combine', () => {
margin: '0px',
},
}

expect(mergeClasses(classes)).to.eql(after)
expect(mergeClasses(classes)).toEqual(after)
})

it('should not return merged classes that are not active', () => {
Expand All @@ -40,8 +36,7 @@ describe('Combine', () => {
margin: '0px',
},
}

expect(mergeClasses(classes, names)).to.eql(after)
expect(mergeClasses(classes, names)).toEqual(after)
})

it('should return basic merged css', () => {
Expand All @@ -64,8 +59,7 @@ describe('Combine', () => {
color: '#333',
},
}

expect(mergeClasses(classes, names)).to.eql(after)
expect(mergeClasses(classes, names)).toEqual(after)
})

it('should return overlaping css', () => {
Expand Down Expand Up @@ -103,8 +97,7 @@ describe('Combine', () => {
color: 'blue',
},
}

expect(mergeClasses(classes, names)).to.eql(after)
expect(mergeClasses(classes, names)).toEqual(after)
})

it('should not mutate default classes when merging', () => {
Expand Down Expand Up @@ -132,9 +125,7 @@ describe('Combine', () => {
margin: '0px',
},
}

expect(mergeClasses(classes, names)).to.eql(after1)
expect(mergeClasses(classes, [])).to.eql(after2)
expect(mergeClasses(classes, names)).toEqual(after1)
expect(mergeClasses(classes, [])).toEqual(after2)
})

})
Loading

0 comments on commit e3b817c

Please sign in to comment.