next-test-helpers
Some useful helpers for integration testing Next.js applications.
Jest example:
/* global jasmine, describe, it, beforeAll, afterAll */ 'use strict' jasmineDEFAULT_TIMEOUT_INTERVAL = 20000
the api
-
setup(dir): build the application pointed to by
dir
. Run withSKIP_BUILD=1
to run against the last app that was built.dir
: path to your Next.js application.
-
teardown(): cleanup after you application.
-
render(path, [query], [req], [res]): render the page pointed to by
path
. Returns a cheerio DOM Element.path
: route to render.query
: query string, this will be passed torender
and populated inreq.url
.req
: the request object, populates with sensible defaults.res
: the response object, populates with sensible defaults.
-
expectElement(element): run a chai-cheerio
expect()
assertion against the element returned byrender
.element
: the element returned by a call torender
.
chai-cheerio examples
See this README for detailed documentation on the chai-cheerio/chai-jquery
assert against text content:
tohavetext'Hello World. About'
using selectors:
tohavetext'www.example.com'
license
ISC