Socket
Book a DemoInstallSign in
Socket

next-test-helper

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-test-helper

test helpers for your next.js applications

latest
Source
npmnpm
Version
1.0.6
Version published
Maintainers
3
Created
Source

next-test-helpers

Build Status Coverage Status Slack Channel

Some useful helpers for integration testing Next.js applications.

Jest example:

/* global jasmine, describe, it, beforeAll, afterAll */

'use strict'

import {expectElement, setup, render, teardown} from 'next-test-helper'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000

describe('next-test-helper', () => {
  beforeAll(async () => await setup('./test/fixtures'))
  afterAll(async () => await teardown())

  it('should render a "hello world" page', async () => {
    const element = await render('/hello')
    expectElement(element).to.have.text('Hello World. About')
  })
})

the api

  • setup(dir): build the application pointed to by dir. Run with SKIP_BUILD=1 to run against the last app that was built.

    • dir: path to your Next.js application.
    beforeAll(async () => await setup('./test/fixtures'))
    
  • teardown(): cleanup after you application.

    afterAll(async () => await teardown())
    
  • 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 to render and populated in req.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 by render.

    • element: the element returned by a call to render.

chai-cheerio examples

See this README for detailed documentation on the chai-cheerio/chai-jquery

assert against text content:

expectElement(element).to.have.text('Hello World. About')

using selectors:

expectElement(
  element.find('#host')
).to.have.text('www.example.com')

license

ISC

Keywords

test

FAQs

Package last updated on 02 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts