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

36 lines
863 B
TypeScript
Raw Normal View History

2022-02-23 22:53:39 +01:00
/*
2021-06-18 13:05:06 +02:00
* @jest-environment jsdom
*/
import Atom, {val} from './Atom'
2022-12-01 15:09:53 +01:00
import prism from './prism/prism'
2021-06-18 13:05:06 +02:00
import Ticker from './Ticker'
2023-01-15 22:04:27 +01:00
describe(`integration`, () => {
2021-06-18 13:05:06 +02:00
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.onChange(ticker, (c) => {
2021-06-18 13:05:06 +02:00
changes.push(c)
})
2023-01-15 12:42:28 +01:00
a.set({...data, bar: 1})
2021-06-18 13:05:06 +02:00
ticker.tick()
expect(changes).toHaveLength(1)
expect(changes[0]).toEqual(1)
2023-01-15 12:42:28 +01:00
a.set({...data, bar: 1})
2021-06-18 13:05:06 +02:00
ticker.tick()
expect(changes).toHaveLength(1)
})
})
})