Skip to content

Commit

Permalink
make test coverage better
Browse files Browse the repository at this point in the history
  • Loading branch information
azazdeaz committed Sep 19, 2015
1 parent e12bafd commit eb7d07d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"isparta": "^3.0.4",
"lodash": "^3.10.1",
"material-ui": "^0.10.0",
"mocha": "^2.3.0",
"mocha": "^2.3.2",
"node-libs-browser": "^0.5.2",
"radium": "^0.13.7",
"raw-loader": "^0.5.1",
Expand Down
24 changes: 13 additions & 11 deletions src/gsap-enhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function enhance (animationSourceMap, ComposedComponent) {
}


//TODO test this
// Class inheritance uses Object.create and because of __proto__ issues
// with IE <10 any static properties of the superclass aren't inherited and
// so need to be manually populated
Expand All @@ -110,17 +111,18 @@ function enhance (animationSourceMap, ComposedComponent) {
// }
// })

if (process.env.NODE_ENV !== 'production') {
// This fixes React Hot Loader by exposing the original components top level
// prototype methods on the Radium enhanced prototype as discussed in #219.
// https://github.com/FormidableLabs/radium/issues/219
Object.keys(ComposedComponent.prototype).forEach(key => {
if (!GSAPEnhancer.prototype.hasOwnProperty(key)) {
var descriptor = Object.getOwnPropertyDescriptor(ComposedComponent.prototype, key)
Object.defineProperty(GSAPEnhancer.prototype, key, descriptor)
}
})
}
//TODO test this
// if (process.env.NODE_ENV !== 'production') {
// // This fixes React Hot Loader by exposing the original components top level
// // prototype methods on the enhanced prototype as discussed in
// // https://github.com/FormidableLabs/radium/issues/219
// Object.keys(ComposedComponent.prototype).forEach(key => {
// if (!GSAPEnhancer.prototype.hasOwnProperty(key)) {
// var descriptor = Object.getOwnPropertyDescriptor(ComposedComponent.prototype, key)
// Object.defineProperty(GSAPEnhancer.prototype, key, descriptor)
// }
// })
// }

return GSAPEnhancer
}
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function attachAll(runningAnimations) {

export function restoreRenderedStyles(itemTree) {
walkItemTree(itemTree, item => {
const savedAttributeNames = Object.keys(item.savedAttributes)
const savedAttributeNames = Object.keys(item.savedAttributes || {})
//restore the original attribute values
savedAttributeNames.forEach(name => {
item.node.setAttribute(name, item.savedAttributes[name])
Expand Down
8 changes: 8 additions & 0 deletions test/gsap-enhancer/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ describe('gsap-enhancer', () => {
const enhancedComponent = new GSAPComponent()
assert.isFunction(enhancedComponent.addAnimation)
assert.isFunction(enhancedComponent.removeAnimation)
assert.isFunction(enhancedComponent.componentDidMount)
assert.isFunction(enhancedComponent.componentWillUpdate)
assert.isFunction(enhancedComponent.componentDidUpdate)
assert.isFunction(enhancedComponent.render)
})

it('enhances without config call', () => {
Expand All @@ -35,12 +39,14 @@ describe('gsap-enhancer', () => {
it('calls the overridden lifecycle methods of the enhanced component', () => {
const willMount = chai.spy()
const didMount = chai.spy()
const willUpdate = chai.spy()
const didUpdate = chai.spy()
const render = chai.spy()

class BaseComponent extends Component {
componentWillMount() {willMount()}
componentDidMount() {didMount()}
componentWillUpdate() {willUpdate()}
componentDidUpdate() {didUpdate()}
render() {
render()
Expand All @@ -53,11 +59,13 @@ describe('gsap-enhancer', () => {

enhancedComponent.componentWillMount()
enhancedComponent.componentDidMount()
enhancedComponent.componentWillUpdate()
enhancedComponent.componentDidUpdate()
enhancedComponent.render()

willMount.should.have.been.called.once()
didMount.should.have.been.called.once()
willUpdate.should.have.been.called.once()
didUpdate.should.have.been.called.once()
render.should.have.been.called.once()
})
Expand Down
22 changes: 20 additions & 2 deletions test/utils/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
var React = require('react')
var FakeNode = require('./FakeNode')
var {
walkItemTree,
reattachAll,
attachAll,
restoreRenderedStyles,
saveRenderedStyles
} = require('../../src/utils')
Expand All @@ -13,6 +11,8 @@ var assert = chai.assert
chai.use(spies)
chai.should()

console.log(process.env.NODE_ENV)

describe('walkItemTree', () => {
it('works nested item tree', () => {
const barItem = {node: {}}
Expand Down Expand Up @@ -68,3 +68,21 @@ describe('saveRenderedStyles & restoreRenderedStyles', () => {
assert.strictEqual(values[names.indexOf('bar')], 'blue')
})
})
describe('attachAll & reattachAll', () => {
const fooNode = new FakeNode({
attributes: {
foo: 'red',
bar: 'blue',
}
})
const fooItem = {node: fooNode}
const itemTree = new Map([['qux', fooItem]])

it('calls animation.attach', () => {
const animation = {
attach: chai.spy()
}
reattachAll(itemTree, [animation])
animation.attach.should.have.been.called.once()
})
})

0 comments on commit eb7d07d

Please sign in to comment.