⚡ Confidently unit and integration test your Next.js API routes/handlers in an isolated Next.js-like environment
MIT License
Bot releases are hidden (Show)
Published by Xunnamius 8 months ago
Published by Xunnamius 9 months ago
Request URLs (e.g. req.url
) default to
"ntarh://testApiHandler/"
.
This is instead of the old localhost string with the random port number, which
is an implementation detail that should not have been exposed to end developers.
NtarhParameters
has been superseded by NtarhInit
,
NtarhInitAppRouter
, and NtarhInitPagesRouter
.
The handler
option of testApiHandler
(i.e.
testApiHandler({ handler })
) has been renamed to pagesHandler
. It is
otherwise functionally equivalent.
Those migrating from NTARH@<4, the process should be as simple as renaming
handler
to pagesHandler
in your tests and getting on with your life.
requestPatcher
, reponsePatcher
, and paramsPatcher
options
of testApiHandler({ ... })
can now be asynchronous and return Promises.
paramsPatcher
can additionally return a brand new params
object that will
overwrite the old one rather than merely augmenting it.
testApiHandler({ ... })
now accepts the appHandler
option.
When this option is provided, the function signatures of the following options
shift to support standard Request
/Response
parameters and return types where
appropriate: requestPatcher
, responsePatcher
, and paramsPatcher
. See the
docs, or intellisense, for more details.
requestPatcher
, reponsePatcher
, and paramsPatcher
options
of testApiHandler({ ... })
no longer support parenthetical shorthand notation.
For example, the following will cause a type error:
testApiHandler({ paramsPatcher: (params) => (params.id = "some-id") })
.
This version of NTARH is now actively tracking a second Next.js
internal export, one that is not guaranteed to be available before
[email protected]
. Therefore, versions of Next.js older than 14.0.4 explicitly
unsupported when using the appHandler
option. On the other hand,
pagesHandler
will always work regardless of Next.js version until Vercel
eventually removes the Pages Router functionality entirely.
The pagesHandler
option of testApiHandler
(i.e.
testApiHandler({ pagesHandler })
) will not accept edge runtime routes. To
test your edge runtime routes, use the appHandler
option instead.
Minimum supported Node.js version is now 18.18.2
Node-fetch has been replaced by Node's native fetch
function. There may be subtle API changes between the two.
NextApiHandler
s (fdfec8c)Published by Xunnamius 12 months ago
Published by Xunnamius about 1 year ago