Files
braidsbymira/src/data/products.test.ts

25 lines
799 B
TypeScript

import { describe, it, expect } from 'vitest'
import { products, getProductsByCategory } from './products'
describe('products data', () => {
it('has at least 6 products with required fields', () => {
expect(products.length).toBeGreaterThanOrEqual(6)
for (const p of products) {
expect(p.id).toBeTruthy()
expect(p.name).toBeTruthy()
expect(p.price).toBeGreaterThan(0)
expect(typeof p.inStock).toBe('boolean')
}
})
it('filters by category', () => {
const hairCare = getProductsByCategory('hair-care')
expect(hairCare.length).toBeGreaterThan(0)
expect(hairCare.every((p) => p.category === 'hair-care')).toBe(true)
})
it('returns all products for "all"', () => {
expect(getProductsByCategory('all')).toHaveLength(products.length)
})
})