mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
renderAndGetWindow does not need jsdom
This commit is contained in:
parent
42dc15e72e
commit
37e7a01955
@ -2,7 +2,6 @@
|
||||
** Test with Ava can be written in ES6 \o/
|
||||
*/
|
||||
import test from 'ava'
|
||||
import jsdom from 'jsdom'
|
||||
import { createServer } from 'http'
|
||||
import { resolve } from 'path'
|
||||
|
||||
@ -39,7 +38,7 @@ test('Route / exits and render HTML', async t => {
|
||||
** Example of testing via dom checking
|
||||
*/
|
||||
test('Route / exits and render HTML', async t => {
|
||||
const window = await nuxt.renderAndGetWindow(jsdom, 'http://localhost:4000/')
|
||||
const window = await nuxt.renderAndGetWindow('http://localhost:4000/')
|
||||
const element = window.document.querySelector('.red-color')
|
||||
t.not(element, null)
|
||||
t.is(element.textContent, 'Hello world!')
|
||||
|
@ -94,7 +94,18 @@ exports.renderRoute = function (url, context = {}) {
|
||||
}
|
||||
|
||||
// Function used to do dom checking via jsdom
|
||||
exports.renderAndGetWindow = function renderAndGetWindow (jsdom, url) {
|
||||
let jsdom = null
|
||||
exports.renderAndGetWindow = function renderAndGetWindow (url) {
|
||||
if (!jsdom) {
|
||||
try {
|
||||
jsdom = require('jsdom')
|
||||
} catch (e) {
|
||||
console.error('Fail when calling nuxt.renderAndGetWindow(url)') // eslint-disable-line no-console
|
||||
console.error('jsdom module is not installed') // eslint-disable-line no-console
|
||||
console.error('Please install jsdom with: npm install --save-dev jsdom') // eslint-disable-line no-console
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
const virtualConsole = jsdom.createVirtualConsole().sendTo(console)
|
||||
url = url || 'http://localhost:3000'
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -1,5 +1,4 @@
|
||||
import test from 'ava'
|
||||
import jsdom from 'jsdom'
|
||||
import { resolve } from 'path'
|
||||
const port = 4002
|
||||
const url = (route) => 'http://localhost:' + port + route
|
||||
@ -31,7 +30,7 @@ test('/stateless', async t => {
|
||||
** Example of testing via dom checking
|
||||
*/
|
||||
test('/css', async t => {
|
||||
const window = await nuxt.renderAndGetWindow(jsdom, url('/css'))
|
||||
const window = await nuxt.renderAndGetWindow(url('/css'))
|
||||
const element = window.document.querySelector('.red')
|
||||
t.not(element, null)
|
||||
t.is(element.textContent, 'This is red')
|
||||
@ -45,7 +44,7 @@ test('/stateful', async t => {
|
||||
})
|
||||
|
||||
test('/head', async t => {
|
||||
const window = await nuxt.renderAndGetWindow(jsdom, url('/head'))
|
||||
const window = await nuxt.renderAndGetWindow(url('/head'))
|
||||
const html = window.document.body.innerHTML
|
||||
const metas = window.document.getElementsByTagName('meta')
|
||||
t.is(window.document.title, 'My title')
|
||||
|
Loading…
Reference in New Issue
Block a user