| 
									
										
										
										
											2020-07-04 18:56:48 +01:00
										 |  |  | describe("errors", () => { | 
					
						
							|  |  |  |     test("cannot spread number in array", () => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             [...1]; | 
					
						
							|  |  |  |         }).toThrowWithMessage(TypeError, "1 is not iterable"); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 18:56:48 +01:00
										 |  |  |     test("cannot spread object in array", () => { | 
					
						
							|  |  |  |         expect(() => { | 
					
						
							|  |  |  |             [...{}]; | 
					
						
							|  |  |  |         }).toThrowWithMessage(TypeError, "[object Object] is not iterable"); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 18:56:48 +01:00
										 |  |  | test("basic functionality", () => { | 
					
						
							|  |  |  |     expect([1, ...[2, 3], 4]).toEqual([1, 2, 3, 4]); | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 18:56:48 +01:00
										 |  |  |     let a = [2, 3]; | 
					
						
							|  |  |  |     expect([1, ...a, 4]).toEqual([1, 2, 3, 4]); | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 18:56:48 +01:00
										 |  |  |     let obj = { a: [2, 3] }; | 
					
						
							|  |  |  |     expect([1, ...obj.a, 4]).toEqual([1, 2, 3, 4]); | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 18:56:48 +01:00
										 |  |  |     expect([...[], ...[...[1, 2, 3]], 4]).toEqual([1, 2, 3, 4]); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2023-08-29 21:38:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | test("allows assignment expressions", () => { | 
					
						
							|  |  |  |     expect("([ ...a = { hello: 'world' } ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a += 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a -= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a **= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a *= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a /= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a %= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a <<= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a >>= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a >>>= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a &= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a ^= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a |= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a &&= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a ||= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("([ ...a ??= 'hello' ])").toEval(); | 
					
						
							|  |  |  |     expect("function* test() { return ([ ...yield a ]); }").toEval(); | 
					
						
							|  |  |  | }); |