mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-02 16:50:38 +00:00
test(utils): use Nuxt.utils
This commit is contained in:
parent
e753f93f97
commit
84350e59c5
@ -1,22 +1,15 @@
|
||||
import test from 'ava'
|
||||
import ansiHTML from 'ansi-html'
|
||||
|
||||
let utils
|
||||
// Init nuxt.js and create server listening on localhost:4000
|
||||
test.before('Init Nuxt.js', async t => {
|
||||
const Nuxt = require('../')
|
||||
let nuxt = new Nuxt({ dev: false })
|
||||
utils = nuxt.utils
|
||||
})
|
||||
import Nuxt from '..'
|
||||
|
||||
test('encodeHtml', t => {
|
||||
const html = '<h1>Hello</h1>'
|
||||
t.is(utils.encodeHtml(html), '<h1>Hello</h1>')
|
||||
t.is(Nuxt.utils.encodeHtml(html), '<h1>Hello</h1>')
|
||||
})
|
||||
|
||||
test('getContext', t => {
|
||||
let ctx = utils.getContext({ a: 1 }, { b: 2 })
|
||||
t.is(utils.getContext.length, 2)
|
||||
let ctx = Nuxt.utils.getContext({ a: 1 }, { b: 2 })
|
||||
t.is(Nuxt.utils.getContext.length, 2)
|
||||
t.is(typeof ctx.req, 'object')
|
||||
t.is(typeof ctx.res, 'object')
|
||||
t.is(ctx.req.a, 1)
|
||||
@ -24,24 +17,24 @@ test('getContext', t => {
|
||||
})
|
||||
|
||||
test('setAnsiColors', t => {
|
||||
utils.setAnsiColors(ansiHTML)
|
||||
Nuxt.utils.setAnsiColors(ansiHTML)
|
||||
t.pass()
|
||||
})
|
||||
|
||||
test('waitFor', async (t) => {
|
||||
let s = Date.now()
|
||||
await utils.waitFor(100)
|
||||
await Nuxt.utils.waitFor(100)
|
||||
t.true(Date.now() - s >= 100)
|
||||
await utils.waitFor()
|
||||
await Nuxt.utils.waitFor()
|
||||
})
|
||||
|
||||
test('urlJoin', t => {
|
||||
t.is(utils.urlJoin('test', '/about'), 'test/about')
|
||||
t.is(Nuxt.utils.urlJoin('test', '/about'), 'test/about')
|
||||
})
|
||||
|
||||
test('promisifyRoute (array)', t => {
|
||||
const array = [1]
|
||||
const promise = utils.promisifyRoute(array)
|
||||
const promise = Nuxt.utils.promisifyRoute(array)
|
||||
t.is(typeof promise, 'object')
|
||||
return promise
|
||||
.then((res) => {
|
||||
@ -54,7 +47,7 @@ test('promisifyRoute (fn => array)', t => {
|
||||
const fn = function () {
|
||||
return array
|
||||
}
|
||||
const promise = utils.promisifyRoute(fn)
|
||||
const promise = Nuxt.utils.promisifyRoute(fn)
|
||||
t.is(typeof promise, 'object')
|
||||
return promise
|
||||
.then((res) => {
|
||||
@ -69,7 +62,7 @@ test('promisifyRoute (fn => promise)', t => {
|
||||
resolve(array)
|
||||
})
|
||||
}
|
||||
const promise = utils.promisifyRoute(fn)
|
||||
const promise = Nuxt.utils.promisifyRoute(fn)
|
||||
t.is(typeof promise, 'object')
|
||||
return promise
|
||||
.then((res) => {
|
||||
@ -81,7 +74,7 @@ test('promisifyRoute (fn(cb) with error)', t => {
|
||||
const fn = function (cb) {
|
||||
cb(new Error('Error here'))
|
||||
}
|
||||
const promise = utils.promisifyRoute(fn)
|
||||
const promise = Nuxt.utils.promisifyRoute(fn)
|
||||
t.is(typeof promise, 'object')
|
||||
return promise
|
||||
.catch((e) => {
|
||||
@ -94,7 +87,7 @@ test('promisifyRoute (fn(cb) with result)', t => {
|
||||
const fn = function (cb) {
|
||||
cb(null, array)
|
||||
}
|
||||
const promise = utils.promisifyRoute(fn)
|
||||
const promise = Nuxt.utils.promisifyRoute(fn)
|
||||
t.is(typeof promise, 'object')
|
||||
return promise
|
||||
.then((res) => {
|
||||
|
Loading…
Reference in New Issue
Block a user