Skip to content

fix: nextResult and nextError return the spy, so they chain - #61

Open
shaurya703 wants to merge 1 commit into
tinylibs:mainfrom
shaurya703:fix/next-result-returns-spy
Open

shaurya703 wants to merge 1 commit into
tinylibs:mainfrom
shaurya703:fix/next-result-returns-spy

Conversation

@shaurya703

Copy link
Copy Markdown

Closes #60

Spy declares nextResult and nextError as returning this, but populateSpy returned the internal state object, which has neither method. So the chain the types allow compiles and then throws at runtime:

const s = spy(() => 'real')
s.nextResult('a').nextResult('b')
// TypeError: s.nextResult(...).nextResult is not a function

This returns the spy from both, the same way willCall in internalSpyOn already does. The two existing call sites in the tests call them as separate statements, so nothing else changes.

Test

One new test pins the identity (nextResult(...) and nextError(...) both toBe the spy) and a mixed chain nextResult(2).nextError(err).nextResult(3), then drains the queue in order. It fails on main with expected { reset: [Function reset], …(7) } to be [Function spy] and passes with the change.

pnpm build && pnpm test: 53/53. tsc --noEmit clean.

`Spy` declares both as returning `this`, but `populateSpy` returned the
internal state, which has neither method. The chain the types promise
compiled and then threw:

    s.nextResult('a').nextResult('b')
    // TypeError: s.nextResult(...).nextResult is not a function

Return the spy, as `willCall` already does, and pin it with a test that
chains through both.

Closes tinylibs#60

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nextResult/nextError return the internal state, not the spy, so chaining throws

1 participant