nuxt-with-jest
nuxt-with-jest copied to clipboard
Trying to set up something similar
trafficstars
Hey! I'm working on getting Jest setup in my own Nuxt project, but I'm running into an issue. I get this big error and I'm not sure why.
● Index page › renders the index route
Webpack build exited with errors
at node_modules/nuxt/dist/nuxt.js:1161:44
at node_modules/webpack/lib/Compiler.js:272:15
at Compiler.emitRecords (node_modules/webpack/lib/Compiler.js:367:37)
at node_modules/webpack/lib/Compiler.js:265:12
at node_modules/webpack/lib/Compiler.js:360:11
at next (node_modules/tapable/lib/Tapable.js:200:11)
at Compiler.compiler.plugin (node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
at Compiler.applyPluginsAsyncSeries1 (node_modules/tapable/lib/Tapable.js:204:13)
at Compiler.afterEmit (node_modules/webpack/lib/Compiler.js:357:8)
at Compiler.<anonymous> (node_modules/webpack/lib/Compiler.js:352:14)
at node_modules/async/dist/async.js:421:16
at iteratorCallback (node_modules/async/dist/async.js:998:13)
at node_modules/async/dist/async.js:906:16
at node_modules/graceful-fs/graceful-fs.js:99:16
at node_modules/graceful-fs/graceful-fs.js:43:10
at node_modules/graceful-fs/graceful-fs.js:43:10
at FSReqWrap.oncomplete (fs.js:111:15)
● Index page › renders the index route
TypeError: this.renderToString is not a function
at Nuxt._callee2$ (node_modules/nuxt/dist/nuxt.js:2040:25)
at tryCatch (node_modules/regenerator-runtime/runtime.js:65:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:303:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:117:21)
at step (node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
at process._tickCallback (internal/process/next_tick.js:103:7)
My test is pretty straightforward, almost identical to yours:
import Nuxt from 'nuxt'
import { resolve } from 'path'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000
let nuxt = null
let server = null
beforeAll(async () => {
const rootDir = resolve(__dirname, '..')
let config = {}
try {
config = require(resolve(rootDir, 'nuxt.config.js'))
} catch (e) {}
config.rootDir = rootDir // project folder
config.dev = false // production build
nuxt = new Nuxt(config)
await nuxt.build()
server = new nuxt.Server(nuxt)
server.listen(4000, 'localhost')
})
describe('Index page', () => {
it('renders the index route', async () => {
let context = {}
const { html } = await nuxt.renderRoute('/', context)
expect(html.includes('<h1 class="title">NUXT</h1>')).toBeTruthy()
})
})
afterAll(() => {
server.close()
nuxt.close()
})
Did you ever run into this? Would love to get it working. Cheers!
@syropian Did you ever figured how to test nuxt route with async jest in nuxt project? I am experiencing the same issue.