-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Add snapshot update feature to promise logic #5132
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ import { | |
createActor, | ||
AnyActorLogic, | ||
Snapshot, | ||
ActorLogic | ||
ActorLogic, | ||
toPromise | ||
} from '../src/index.ts'; | ||
import { | ||
fromCallback, | ||
|
@@ -464,6 +465,44 @@ describe('promise logic (fromPromise)', () => { | |
const fn2 = signalListenerList[1]; | ||
expect(fn2).toHaveBeenCalled(); | ||
}); | ||
|
||
it('can emit updates', async () => { | ||
const p = fromPromise(async ({ update }) => { | ||
update({ value: 'starting' }); | ||
update({ value: 'loading', context: { progress: 0.6 } }); | ||
update({ value: 'finished' }); | ||
return 'done data'; | ||
}); | ||
|
||
const stuff: Array<{}> = []; | ||
|
||
const actor = createActor(p); | ||
actor.subscribe((s) => { | ||
stuff.push(s); | ||
}); | ||
actor.start(); | ||
|
||
const res = await toPromise(actor); | ||
|
||
expect(res).toEqual('done data'); | ||
|
||
expect(stuff).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it feels like a better "assertion" could be put here, this one looks suspicious - maybe we could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then it would make sense to include the status in all of those assertions~ |
||
expect.objectContaining({ value: 'starting', context: undefined }), | ||
expect.objectContaining({ | ||
value: 'loading', | ||
context: { progress: 0.6 } | ||
}), | ||
expect.objectContaining({ value: 'finished', context: undefined }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this test case is too big. "can emit updates" is too broad and doesn't give me much insight into what is actually expected because it reads as "it works". For instance, I noticed that an update with just one of those fields would wipe out the other one. I was wondering how deliberate that was and if we have a test for it. It turns out we do - but it's just so buried in this item here. It's hard to tell if this was intentional or accidental. I think it was intentional and that's fine - but my point stands: a test with so many details in it isn't particularly informative/explicit about its intentions |
||
expect.objectContaining({ | ||
status: 'done', | ||
output: 'done data', | ||
value: 'finished' | ||
}) | ||
]) | ||
); | ||
}); | ||
}); | ||
|
||
describe('transition function logic (fromTransition)', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice to add some type-level tests for usage with discriminated unions, including tests that would exercise
.getSnapshot()