From f296d47a8968971faf52dcc83e96a7e6243bddf4 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 19 Sep 2024 23:27:46 +0200 Subject: [PATCH] chore: wip --- .../framework/core/collections/package.json | 1 + .../collections/tests/collections.test.ts | 31 +++++++++++++++++++ .../core/collections/tests/example.test.ts | 5 --- 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 storage/framework/core/collections/tests/collections.test.ts delete mode 100644 storage/framework/core/collections/tests/example.test.ts diff --git a/storage/framework/core/collections/package.json b/storage/framework/core/collections/package.json index f0e7de952e..d27809c933 100644 --- a/storage/framework/core/collections/package.json +++ b/storage/framework/core/collections/package.json @@ -41,6 +41,7 @@ "scripts": { "build": "bun --bun build.ts", "typecheck": "bun --bun tsc --noEmit", + "test": "bun --bun test", "prepublishOnly": "bun run build" }, "dependencies": { diff --git a/storage/framework/core/collections/tests/collections.test.ts b/storage/framework/core/collections/tests/collections.test.ts new file mode 100644 index 0000000000..c85db156d5 --- /dev/null +++ b/storage/framework/core/collections/tests/collections.test.ts @@ -0,0 +1,31 @@ +import { Collection, collect } from '../src/index' + +describe('@stacksjs/collections', () => { + it('exports Collection and collect from collect.js', () => { + expect(Collection).toBeDefined() + expect(collect).toBeDefined() + }) + + it('can create a collection', () => { + const collection = collect([1, 2, 3]) + expect(collection).toBeInstanceOf(Collection) + expect(collection.all()).toEqual([1, 2, 3]) + }) + + it('can use collection methods', () => { + const collection = collect([1, 2, 3, 4, 5]) + + expect(collection.sum()).toBe(15) + expect(collection.average()).toBe(3) + expect(collection.map((n) => n * 2).all()).toEqual([2, 4, 6, 8, 10]) + }) + + it('can chain methods', () => { + const result = collect([1, 2, 3, 4, 5]) + .filter((n) => n % 2 === 0) + .map((n) => n * 2) + .all() + + expect(result).toEqual([4, 8]) + }) +}) diff --git a/storage/framework/core/collections/tests/example.test.ts b/storage/framework/core/collections/tests/example.test.ts deleted file mode 100644 index ca8394afb7..0000000000 --- a/storage/framework/core/collections/tests/example.test.ts +++ /dev/null @@ -1,5 +0,0 @@ -describe('example test', () => { - it('assert', () => { - expect(1).toBe(1) - }) -})