From 8a6a6712e7554f110b5ef951f270d88fd010e040 Mon Sep 17 00:00:00 2001 From: Bertrand Yuan Date: Thu, 26 Mar 2026 00:02:16 +0800 Subject: add more tests --- src/lib/is-active.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/lib/is-active.test.ts (limited to 'src/lib/is-active.test.ts') diff --git a/src/lib/is-active.test.ts b/src/lib/is-active.test.ts new file mode 100644 index 0000000..fcc42d0 --- /dev/null +++ b/src/lib/is-active.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, test } from 'vitest'; +import { isActive } from './is-active'; + +describe('isActive', () => { + test('returns true for exact match', () => { + expect(isActive('/posts', '/posts')).toBe(true); + }); + + test('normalizes trailing slashes before comparing', () => { + expect(isActive('/posts/', '/posts')).toBe(true); + expect(isActive('/posts', '/posts/')).toBe(true); + }); + + test('returns true for nested paths when nested is enabled', () => { + expect(isActive('/posts', '/posts/hello-world', true)).toBe(true); + }); + + test('returns false for nested paths when nested is disabled', () => { + expect(isActive('/posts', '/posts/hello-world', false)).toBe(false); + }); + + test('returns false for unrelated paths', () => { + expect(isActive('/posts', '/tags')).toBe(false); + }); +}); + -- cgit v1.2.3