Skip to content

Commit f296d47

Browse files
committed
chore: wip
1 parent 33f85b6 commit f296d47

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

storage/framework/core/collections/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"scripts": {
4242
"build": "bun --bun build.ts",
4343
"typecheck": "bun --bun tsc --noEmit",
44+
"test": "bun --bun test",
4445
"prepublishOnly": "bun run build"
4546
},
4647
"dependencies": {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Collection, collect } from '../src/index'
2+
3+
describe('@stacksjs/collections', () => {
4+
it('exports Collection and collect from collect.js', () => {
5+
expect(Collection).toBeDefined()
6+
expect(collect).toBeDefined()
7+
})
8+
9+
it('can create a collection', () => {
10+
const collection = collect([1, 2, 3])
11+
expect(collection).toBeInstanceOf(Collection)
12+
expect(collection.all()).toEqual([1, 2, 3])
13+
})
14+
15+
it('can use collection methods', () => {
16+
const collection = collect([1, 2, 3, 4, 5])
17+
18+
expect(collection.sum()).toBe(15)
19+
expect(collection.average()).toBe(3)
20+
expect(collection.map((n) => n * 2).all()).toEqual([2, 4, 6, 8, 10])
21+
})
22+
23+
it('can chain methods', () => {
24+
const result = collect([1, 2, 3, 4, 5])
25+
.filter((n) => n % 2 === 0)
26+
.map((n) => n * 2)
27+
.all()
28+
29+
expect(result).toEqual([4, 8])
30+
})
31+
})

storage/framework/core/collections/tests/example.test.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)