From 84350e59c50c75063b6752599d09bec2f7439291 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 13 Jun 2017 00:06:52 +0430 Subject: [PATCH] test(utils): use Nuxt.utils --- test/utils.test.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/test/utils.test.js b/test/utils.test.js index 3a2aff00ff..71a269a27f 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -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 = '

Hello

' - 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) => {