Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

refract-xstream

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

refract-xstream - npm Package Compare versions

Comparing version 1.0.0-0 to 1.0.0-1

src/__tests__/effectFactory.ts

2

package.json
{
"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'
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc