Reset polling on init#21
Conversation
This is most relevant to react tests since there's a single global `prefab` object, but if you `init` after starting polling, the previous polling shouldn't continue.
| if (!prefab.loader) { | ||
| throw new Error('Expected loader to be set'); | ||
| } |
There was a problem hiding this comment.
You may want to write these as expectations instead?
| if (!prefab.loader) { | |
| throw new Error('Expected loader to be set'); | |
| } | |
| expect(prefab.loader).not.toBeNull(); |
There was a problem hiding this comment.
A reasonable thing to suggest. But if I do that, I still have to guard against this being undefined or when I later call prefab.loader.context typescript complains error TS18048: 'prefab.loader' is possibly 'undefined'.
There are other ways to handle this, but IME this is the simplest way to handle it in test code.
If you have a succinct preferred approach, please do tell!
There was a problem hiding this comment.
Ahhhh, good ol' typescript doesn't pick up the guards from the expectations in jest yet without writing wrapper functions per this PR: microsoft/TypeScript#32695
👍 keep on trucking.
| if (prefab.pollStatus.status !== 'running') { | ||
| throw new Error('Expected pollStatus to be running'); | ||
| } |
There was a problem hiding this comment.
| if (prefab.pollStatus.status !== 'running') { | |
| throw new Error('Expected pollStatus to be running'); | |
| } | |
| expect(prefab.pollStatus.status).toEqual('running'); |
This is most relevant to react tests since there's a single global
prefabobject, but if youinitafter starting polling, the previouspolling shouldn't continue.