Skip to content

Commit

Permalink
More tests for new computed
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeistrich committed Oct 6, 2023
1 parent 523db89 commit 77bd898
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2968,12 +2968,31 @@ describe('new computed', () => {
await promiseTimeout(0);
expect(obs.child.test.get()).toEqual('hello');
});
test('new computed as a computed', () => {
const other = observable('hi');

// @ts-expect-error asdf
const obs = observable<{ child: { test: string } }>({
child: () => {
return {
test: other.get(),
};
},
});
expect(obs.child.test.get()).toEqual('hi');

other.set('hello');

expect(obs.child.test.get()).toEqual('hello');
});
test('new computed with onChange and onSet', async () => {
let wasSetTo: any;
let numRuns = 0;
// @ts-expect-error asdf
const obs = observable<{ child: { test: string } }>({
// @ts-expect-error asdf
child: ({ onSet, subscribe }) => {
numRuns++;
// @ts-expect-error asdf
onSet(({ value }) => {
wasSetTo = value;
Expand All @@ -2995,6 +3014,7 @@ describe('new computed', () => {

expect(obs.child.test.get()).toEqual('hello');
expect(wasSetTo).toEqual({ test: 'hello' });
expect(numRuns).toEqual(1); // Only runs once because there's no observables
});
test('new computed with onChange and onSet other observable', async () => {
const other = observable('hi');
Expand Down

0 comments on commit 77bd898

Please sign in to comment.