apeman-react-mixins
Version:
React mixin set of apeman.
62 lines (54 loc) • 1.45 kB
JavaScript
/**
* Test case for apSpinMixin.
* Runs with mocha.
*/
const ApSpinMixin = require('../lib/ap_spin_mixin.js').default
const React = require('react')
const ReactDOM = require('react-dom/server')
const assert = require('assert')
describe('ap-spin-mixin', () => {
before((done) => {
done()
})
after((done) => {
done()
})
it('Ap spin mixin', (done) => {
const MockClass = React.createClass({
mixins: [
ApSpinMixin
],
render () {
const s = this
return React.createElement('div', {},
s.props.children
)
},
componentWillMount () {
const s = this
assert.ok(!s.hasSpin('hoge'))
s.incrementSpinCount('hoge')
s.incrementSpinCount('fuge')
assert.ok(s.hasSpin('hoge'))
assert.ok(s.hasSpin('fuge'))
assert.equal(s.getSpinCount('hoge'), 1)
s.decrementSpinCount('hoge')
assert.ok(!s.hasSpin('hoge'))
assert.equal(s.getSpinCount('hoge'), 0)
assert.ok(s.hasSpin('fuge'))
s.resetSpinCount('fuge')
assert.equal(s.getSpinCount('fuge'), 0)
assert.ok(!s.hasSpin('fuge'))
s.spinWhile('hoge', ()=> {
return Promise.resolve('hoge')
})
}
})
let root = React.createElement(MockClass, {})
let html = ReactDOM.renderToString(root)
assert.ok(html)
done()
})
})
/* global describe, before, after, it */