Skip to content

docs: add an API reference to the README - #59

Open
shaurya703 wants to merge 1 commit into
tinylibs:mainfrom
shaurya703:docs/api-reference
Open

shaurya703 wants to merge 1 commit into
tinylibs:mainfrom
shaurya703:docs/api-reference

Conversation

@shaurya703

Copy link
Copy Markdown

Closes #40

The README showed usage but never documented the surface, so there was nothing to point at for what a given export or property does. This adds a reference covering every symbol on the checklist in #40:

  • spy, spyOn, restoreAll
  • shared spy properties β€” called, callCount, calls, results, resolves, returns, length, impl, reset, nextResult, nextError
  • spyOn-only methods β€” getOriginal, willCall, restore, and the Symbol.dispose / using form
  • the internal exports vitest builds on β€” spies, createInternalSpy, internalSpyOn, getInternalState

It also writes down behaviour that wasn't documented anywhere: the argument errors each guard throws, that spyOn resolves along the prototype chain, that the mock argument is optional, that spy() spies are never added to spies, and that the nextResult/nextError queue is FIFO and consumed once per entry.

Corrections

Four existing examples were wrong:

  • results and resolves hold tuples, so they print as [['ok', ...]], not ['ok', ...] β€” three places
  • the last restore example called obj.restore(), but the spy is bound to spy, so it's spy.restore()

Verification

Every example was executed against the build rather than written from reading the source β€” all 18 assertions pass, including the using block.

52 tests still pass. The file was prettier-clean before this change and is after it, and the only deletions in the diff are the four corrections above.

Closes tinylibs#40

The README showed usage but never documented the surface, so there was
nothing to point at for what a given export or property does. This adds
a reference covering every symbol on the checklist in tinylibs#40:

  - spy, spyOn, restoreAll
  - shared spy properties: called, callCount, calls, results, resolves,
    returns, length, impl, reset, nextResult, nextError
  - spyOn-only methods: getOriginal, willCall, restore, and the
    Symbol.dispose/`using` form
  - the internal exports vitest builds on: spies, createInternalSpy,
    internalSpyOn, getInternalState

It also documents behaviour that was not written down anywhere: the
argument errors each guard throws, that `spyOn` resolves along the
prototype chain, that a mock argument is optional, that `spy()` spies
are never added to `spies`, and that the nextResult/nextError queue is
FIFO and consumed once per entry.

Four existing examples were wrong and are corrected:

  - `results` and `resolves` hold tuples, so they print as
    [['ok', ...]], not ['ok', ...] (three places)
  - the last restore example called `obj.restore()`; the spy is bound to
    `spy`, so it is `spy.restore()`

Every example was executed against the build rather than written from
reading the source; all 18 assertions pass, including the `using` block.
52 tests still pass and prettier is clean β€” the file was prettier-clean
before this change and the only deletions in the diff are the four
corrections above.

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.

Full documentation

1 participant