theatre/packages/dataverse/src/integration.test.ts

37 lines
914 B
TypeScript
Raw Normal View History

2021-06-18 13:05:06 +02:00
/**
2021-10-02 14:12:25 +02:00
// eslint-disable-next-line
2021-06-18 13:05:06 +02:00
* @jest-environment jsdom
*/
import Atom, {val} from './Atom'
import prism from './derivations/prism/prism'
import Ticker from './Ticker'
describe(`v2 atom`, () => {
describe(`identity pointers`, () => {
it(`should work`, () => {
const data = {foo: 'hi', bar: 0}
const a = new Atom(data)
const dataP = a.pointer
const bar = dataP.bar
expect(val(bar)).toEqual(0)
const d = prism(() => {
return val(bar)
})
expect(d.getValue()).toEqual(0)
const ticker = new Ticker()
const changes: number[] = []
d.changes(ticker).tap((c) => {
changes.push(c)
})
a.setState({...data, bar: 1})
ticker.tick()
expect(changes).toHaveLength(1)
expect(changes[0]).toEqual(1)
a.setState({...data, bar: 1})
ticker.tick()
expect(changes).toHaveLength(1)
})
})
})