common.test.js 825 B

123456789101112131415161718192021222324252627
  1. import { describe, expect, test } from 'vitest'
  2. import { calcItog } from '../common.js'
  3. const item100_1 = {title:'test',price:100,quantity:1}
  4. const item50_2 = {title:'test',price:50,quantity:2}
  5. describe('Расчет итога корзины', () => {
  6. test('Пустая корзина', () => {
  7. const cart = []
  8. expect(calcItog(cart)).toBe(0)
  9. })
  10. test('В корзине одно блюдо в одном экземпляре', () => {
  11. const cart = [item100_1]
  12. expect(calcItog(cart)).toBe(100)
  13. })
  14. test('В корзине одно блюдо в двух экземплярах', () => {
  15. const cart = [item50_2]
  16. expect(calcItog(cart)).toBe(100)
  17. })
  18. test('В корзине два блюда', () => {
  19. const cart = [item100_1, item50_2]
  20. expect(calcItog(cart)).toBe(200)
  21. })
  22. })