From bec4e6ed5d086cce3cc9a26b8566d5b4c911e201 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Sun, 6 Nov 2022 21:07:53 +0800 Subject: [PATCH] test(list_route): improve coverage (#5097) --- test/scripts/console/index.js | 1 + test/scripts/console/list_route.js | 31 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/scripts/console/list_route.js diff --git a/test/scripts/console/index.js b/test/scripts/console/index.js index 2c9a1d2208..94ef2ffd02 100644 --- a/test/scripts/console/index.js +++ b/test/scripts/console/index.js @@ -14,4 +14,5 @@ describe('Console', () => { require('./list_categories'); require('./list_tags'); require('./list_page'); + require('./list_route'); }); diff --git a/test/scripts/console/list_route.js b/test/scripts/console/list_route.js new file mode 100644 index 0000000000..ae3892884b --- /dev/null +++ b/test/scripts/console/list_route.js @@ -0,0 +1,31 @@ +'use strict'; + +const { stub, assert: sinonAssert } = require('sinon'); + +describe('Console list', () => { + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); + + const listRoutes = require('../../../lib/plugins/console/list/route').bind(hexo); + const { route } = hexo; + + let logStub; + + before(() => { logStub = stub(console, 'log'); }); + + afterEach(() => { logStub.reset(); }); + + after(() => { logStub.restore(); }); + + it('no route', () => { + listRoutes(); + sinonAssert.calledWithMatch(logStub, 'Total: 0'); + }); + + it('route', async () => { + route.set('test', 'foo'); + + listRoutes(); + sinonAssert.calledWithMatch(logStub, 'Total: 1'); + }); +});