1.0.6 • Published 7 years ago

next-test-helper v1.0.6

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

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

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago