Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Next.js article #223

Open
wants to merge 1 commit into
base: versions/2.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions guide/component-testing/testing-nextjs-components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Next.js component testing
description: Learn how to do write and execute Next.js component tests in Nightwatch.
---
<div class="page-header"><h1>NextJS component testing in Nightwatch</h1></div>

### Overview
[Next.js][1], developed by [Vercel][2], is a framework built on top of React. NextJS component testing setup with Nightwatch is the same as React component testing setup. Next.js makes full stack web development easier by extending the latest React functionality. The Rust based Javacript tooling integrated into the framework makes the builds blazing fast.

### Installation

#### New Project
When you initiate a Nightwatch project using
<pre class="hide-indicator"><code class="language-bash">npm init nightwatch@latest</code></pre>

select component testing and React.js and let Nightwatch handle the setup for you.


#### Existing Project
Follow the same steps as [React component testing installation][3]

### Testing NextJS components
Simply mount the component using the `mountComponent('path_to_component_file')` command and write your tests like you would for any other test.


<div class="sample-test"><i>NextJS component test</i><pre class="line-numbers language-javascript"><code class="language-javascript">describe('Next.js test', function() {
it('NextJS component testing', async function(browser) {
browser
.mountComponent("/src/components/About.jsx")
.assert.textEquals("h1","About");
});
});
</code></pre></div>

[1]: https://nextjs.org/
[2]: https://vercel.com/
[3]: https://nightwatchjs.org/guide/component-testing/testing-react-components.html#installation