@@ -6,6 +6,11 @@ describe("Testing de la clase Carrito", () => {
66 name : "sushiItem" ,
77 } ;
88
9+ const waterItem = {
10+ price : 1.5 ,
11+ name : "waterItem" ,
12+ } ;
13+
914 let carrito ;
1015 beforeEach ( ( ) => {
1116 carrito = new Carrito ( ) ;
@@ -59,12 +64,67 @@ describe("Testing de la clase Carrito", () => {
5964 } ) ;
6065
6166 describe ( "Testeando getTotalCheckout" , ( ) => {
67+ it ( "Carrito.getTotatCheckout debe devolver 10 despues de añadir 1 sushiItem" , ( ) => {
68+ carrito . addItem ( sushiItem ) ;
69+ expect ( carrito . getTotatCheckout ( ) ) . toEqual ( 10 ) ;
70+ } ) ;
71+
72+ it ( "Carrito.getTotatCheckout debe devolver 20 despues de añadir 2 sushiItem" , ( ) => {
73+ carrito . addItem ( sushiItem ) ;
74+ carrito . addItem ( sushiItem ) ;
75+ expect ( carrito . getTotatCheckout ( ) ) . toEqual ( 20 ) ;
76+ } ) ;
77+
78+ it ( "Carrito.getTotatCheckout debe devolver 11,5 despues de añadir 1 sushiItem i 1 waterItem" , ( ) => {
79+ carrito . addItem ( sushiItem ) ;
80+ carrito . addItem ( waterItem ) ;
81+ expect ( carrito . getTotatCheckout ( ) ) . toEqual ( 11.5 ) ;
82+ } ) ;
83+
84+ it ( "Debe devolver 0 si el carrito esta vacío" , ( ) => {
85+ expect ( carrito . getTotatCheckout ( ) ) . toEqual ( 0 ) ;
86+ } ) ;
87+ } ) ;
88+
89+ describe ( "Testeando addItem (detail)" , ( ) => {
90+ it ( "Debe contener el item añadido en la propiedad carrito.items" , ( ) => {
91+ carrito . addItem ( sushiItem ) ;
92+ expect ( carrito . items ) . toPartiallyContain ( sushiItem ) ;
93+ } ) ;
94+
95+ it ( "Carrito.items debe ser un array vacío si no añadimos ningun elemento" , ( ) => {
96+ expect ( carrito . items ) . toBeEmpty ( ) ;
97+ } ) ;
98+
99+ it ( "Carrito debe llamar a una función checkItem antes de añadirlo al carrito." , ( ) => {
100+ const spy = jest . spyOn ( carrito , "checkItem" ) ;
101+ carrito . addItem ( sushiItem ) ;
102+ // expect(jest.spyOn(carrito, 'checkItem')).toHaveBeenCalled(); Es lo mismo que definir una variable.
103+ expect ( spy ) . toHaveBeenCalled ( ) ;
104+ } ) ;
105+
106+ it ( "Carrito debe llamar una única vez a checkItem cuando añadimos un elemento" , ( ) => {
107+ const spy = jest . spyOn ( carrito , "checkItem" ) ;
108+ carrito . addItem ( sushiItem ) ;
109+ expect ( spy ) . toHaveBeenCalledOnce ( ) ;
110+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
111+ } ) ;
112+
113+ it ( "Carrito debe llamar a una función checkItem con el valor del item a añadir" , ( ) => {
114+ const spy = jest . spyOn ( carrito , "checkItem" ) ;
115+ carrito . addItem ( sushiItem ) ;
116+ expect ( spy ) . toHaveBeenCalledWith ( sushiItem ) ;
117+ } ) ;
118+ } ) ;
119+
120+ describe ( "Testeando removeItem" , ( ) => {
121+ it ( "Carrito.removeItem debe devolver un array vacio despues de añadir un elemento y eliminarlo" , ( ) => {
122+ carrito . addItem ( waterItem ) ;
123+ expect ( carrito . removeItem ( waterItem ) ) . toHaveLength ( 0 ) ;
124+ } ) ;
125+
62126 it . todo (
63- "Carrito.getTotatCheckout debe devolver 10 despues de añadir 1 sushiItem" ,
64- ( ) => {
65- carrito . addItem ( sushiItem ) ;
66- expect ( carrito . getTotalCheckout ( ) ) . toEqual ( 1 ) ;
67- }
127+ "Carrito.removeItem debe devolver un array con un elemento cuando añadimos dos elementos distintos y eliminamos uno"
68128 ) ;
69129 } ) ;
70130} ) ;
0 commit comments