This repository has been archived by the owner on Aug 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from FormidableLabs/enhancer-test
Enhancer tests and examples
- Loading branch information
Showing
6 changed files
with
149 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
var ReactTools = require('react-tools'); | ||
var babel = require('babel'); | ||
var path = require('path'); | ||
|
||
var targetPath = path.resolve(__dirname + '/../modules'); | ||
|
||
module.exports = { | ||
process: function(src) { | ||
return ReactTools.transform(src); | ||
process: function(src, file) { | ||
// Keep it fast by only running babel over Radium code | ||
if (file.indexOf(targetPath) !== 0) { | ||
return src; | ||
} | ||
|
||
return babel.transform(src).code; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* eslint-env jasmine */ | ||
/* global jest */ | ||
|
||
'use strict'; | ||
|
||
jest.dontMock('../enhancer.js'); | ||
jest.dontMock('../wrap-utils.js'); | ||
|
||
var resolveStyles = require('../resolve-styles.js'); | ||
var Enhancer = require('../enhancer.js'); | ||
|
||
var {Component} = require('react'); | ||
|
||
describe('Enhancer', () => { | ||
it('sets up initial state', () => { | ||
class Composed extends Component { } | ||
var Enhanced = Enhancer(Composed); | ||
|
||
var instance = new Enhanced(); | ||
|
||
expect(instance.state).toEqual({_radiumStyleState: {}}); | ||
}); | ||
|
||
it('merges with existing state', () => { | ||
class Composed extends Component { | ||
constructor () { | ||
super(); | ||
this.state = {foo: 'bar'}; | ||
} | ||
} | ||
var Enhanced = Enhancer(Composed); | ||
|
||
var instance = new Enhanced(); | ||
|
||
|
||
expect(instance.state).toEqual( | ||
{foo: 'bar', _radiumStyleState: {}} | ||
); | ||
}); | ||
|
||
it('calls existing render function, then resolveStyles', () => { | ||
var renderMock = jest.genMockFunction(); | ||
class Composed extends Component { | ||
render () { | ||
renderMock(); | ||
return null; | ||
} | ||
} | ||
var Enhanced = Enhancer(Composed); | ||
|
||
var instance = new Enhanced(); | ||
instance.render(); | ||
|
||
expect(renderMock).toBeCalled(); | ||
expect(resolveStyles).toBeCalled(); | ||
}); | ||
|
||
it('calls existing componentWillUnmount function', () => { | ||
var existingComponentWillUnmount = jest.genMockFunction(); | ||
class Composed extends Component { | ||
componentWillUnmount () { | ||
existingComponentWillUnmount(); | ||
} | ||
} | ||
var Enhanced = Enhancer(Composed); | ||
|
||
var instance = new Enhanced(); | ||
instance.componentWillUnmount(); | ||
|
||
expect(existingComponentWillUnmount).toBeCalled(); | ||
}); | ||
|
||
it('removes mouse up listener on componentWillUnmount', () => { | ||
var removeMouseUpListener = jest.genMockFunction(); | ||
class Composed extends Component { | ||
constructor () { | ||
super(); | ||
this._radiumMouseUpListener = { remove: removeMouseUpListener }; | ||
} | ||
} | ||
var Enhanced = Enhancer(Composed); | ||
|
||
var instance = new Enhanced(); | ||
instance.componentWillUnmount(); | ||
|
||
expect(removeMouseUpListener).toBeCalled(); | ||
}); | ||
|
||
it('removes media query listeners on componentWillUnmount', () => { | ||
var mediaQueryListenersByQuery = { | ||
'(min-width: 1000px)': { remove: jest.genMockFunction() }, | ||
'(max-width: 600px)': { remove: jest.genMockFunction() }, | ||
'(min-resolution: 2dppx)': { remove: jest.genMockFunction() } | ||
}; | ||
class Composed extends Component { | ||
constructor () { | ||
super(); | ||
this._radiumMediaQueryListenersByQuery = mediaQueryListenersByQuery; | ||
} | ||
} | ||
var Enhanced = Enhancer(Composed); | ||
|
||
var instance = new Enhanced(); | ||
instance.componentWillUnmount(); | ||
|
||
Object.keys(mediaQueryListenersByQuery).forEach(function (key) { | ||
expect(mediaQueryListenersByQuery[key].remove).toBeCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters