From 6385b7fa45f6397ec866993086248cf1260c3779 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Sat, 21 Nov 2020 09:05:49 +0800 Subject: [PATCH] Update --- src/core/render/tpl.js | 3 +-- test/unit/render-util.test.js | 46 +++++++++++++++++------------------ 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/core/render/tpl.js b/src/core/render/tpl.js index 91f990feb..595cdff76 100644 --- a/src/core/render/tpl.js +++ b/src/core/render/tpl.js @@ -90,9 +90,8 @@ export function tree(toc, tpl = '') { } let innerHTML = ''; - let title = ''; toc.forEach(node => { - title = node.title.replace(/(<([^>]+)>)/g, ''); + const title = node.title.replace(/(<([^>]+)>)/g, ''); innerHTML += `
  • ${node.title}
  • `; if (node.children) { innerHTML += tree(node.children, tpl); diff --git a/test/unit/render-util.test.js b/test/unit/render-util.test.js index be4897879..5d556168f 100644 --- a/test/unit/render-util.test.js +++ b/test/unit/render-util.test.js @@ -16,30 +16,28 @@ describe('core/render/utils', () => { }); describe('core/render/tpl', () => { - describe('remove html tag in tree', () => { - test('remove span and img', () => { - const result = tree([ - { - level: 2, - slug: '#/cover?id=basic-usage', - title: 'Basic usage', - }, - { - level: 2, - slug: '#/cover?id=custom-background', - title: 'Custom background', - }, - { - level: 2, - slug: '#/cover?id=test', - title: - 'icoTest', - }, - ]); + test('remove html tag in tree', () => { + const result = tree([ + { + level: 2, + slug: '#/cover?id=basic-usage', + title: 'Basic usage', + }, + { + level: 2, + slug: '#/cover?id=custom-background', + title: 'Custom background', + }, + { + level: 2, + slug: '#/cover?id=test', + title: + 'icoTest', + }, + ]); - expect(result).toEqual( - `` - ); - }); + expect(result).toEqual( + `` + ); }); });