refract-xstream
Advanced tools
Comparing version 1.0.0-0 to 1.0.0-1
{ | ||
"name": "refract-xstream", | ||
"version": "1.0.0-0", | ||
"version": "1.0.0-1", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "jsnext:main": "index.es.js", |
@@ -1,17 +0,7 @@ | ||
import { | ||
withEffects, | ||
EffectHandler, | ||
EffectFactory, | ||
ObservableComponent | ||
} from '../index' | ||
import * as React from 'react' | ||
import { withEffects, EffectHandler, ObservableComponent } from '../index' | ||
import effectFactory, { Effect, Props } from './effectFactory' | ||
import { shallow, mount } from 'enzyme' | ||
describe('refract-xstream', () => { | ||
interface Effect { | ||
type: string | ||
value: number | ||
} | ||
interface Props { | ||
value: number | ||
} | ||
describe('refract-rxjs', () => { | ||
const noop = (...args) => void 0 | ||
@@ -25,16 +15,60 @@ | ||
const effectFactory: EffectFactory<Props, Effect> = props => component => { | ||
const value$ = component.observe<number>('value') | ||
it('should create a HoC', () => { | ||
const WithEffects = withEffects<Props, Effect>(effectHandler)( | ||
effectFactory | ||
)(() => React.createElement('div')) | ||
}) | ||
return value$.map(value => ({ | ||
type: 'MyEffect', | ||
value | ||
})) | ||
} | ||
it('should observe component changes', () => { | ||
const effectValueHandler = jest.fn() | ||
const setValue = () => void 0 | ||
const WithEffects = withEffects<Props, Effect>( | ||
() => effectValueHandler | ||
)(effectFactory)(({ setValue }) => | ||
React.createElement('button', { | ||
onClick: () => setValue(10) | ||
}) | ||
) | ||
const withEffectsHOC = withEffects<Props, Effect>(effectHandler) | ||
const component = mount( | ||
React.createElement(WithEffects, { value: 1, setValue }) | ||
) | ||
it('should create a HoC', () => { | ||
const WithEffects = withEffectsHOC(effectFactory) | ||
expect(component.prop('value')).toBe(1) | ||
expect(effectValueHandler).toHaveBeenCalledWith({ | ||
type: 'ValueChange', | ||
value: 1 | ||
}) | ||
expect(effectValueHandler).toHaveBeenCalledWith({ | ||
type: 'Start' | ||
}) | ||
component.setProps({ value: 2 }) | ||
expect(effectValueHandler).toHaveBeenCalledWith({ | ||
type: 'ValueChange', | ||
value: 2 | ||
}) | ||
component.simulate('click') | ||
expect(effectValueHandler).toHaveBeenCalledWith({ | ||
type: 'ValueSet', | ||
value: 10 | ||
}) | ||
component.setProps({ setValue: () => void 0 }) | ||
component.simulate('click') | ||
expect(effectValueHandler).toHaveBeenCalledWith({ | ||
type: 'ValueSet', | ||
value: 10 | ||
}) | ||
component.unmount() | ||
expect(effectValueHandler).toHaveBeenCalledWith({ | ||
type: 'Stop' | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24627
14
586