Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Sep 19, 2024
1 parent 33f85b6 commit f296d47
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions storage/framework/core/collections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"scripts": {
"build": "bun --bun build.ts",
"typecheck": "bun --bun tsc --noEmit",
"test": "bun --bun test",
"prepublishOnly": "bun run build"
},
"dependencies": {
Expand Down
31 changes: 31 additions & 0 deletions storage/framework/core/collections/tests/collections.test.ts
Original file line number Diff line number Diff line change
@@ -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])
})
})
5 changes: 0 additions & 5 deletions storage/framework/core/collections/tests/example.test.ts

This file was deleted.

0 comments on commit f296d47

Please sign in to comment.