From d35bb00f31364d48e3f0a5b415bf6b187267ac3b Mon Sep 17 00:00:00 2001 From: Andrew Harasymiw Date: Wed, 9 Aug 2023 08:39:40 -0700 Subject: [PATCH] Our test to make sure the listItems function cleared the basket and then added two items. We left those two items in the basket! This update re-clears the basket after our assert statements, to make sure we aren't leaving side effects. --- test/test.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/test.js b/test/test.js index 2cd1a046..71abed0a 100644 --- a/test/test.js +++ b/test/test.js @@ -38,15 +38,15 @@ describe('Automated tests', function () { before(function () { // runs once before the first test in this block let { basket } = testItems; - if(typeof basket === 'array') { + if (typeof basket === 'array') { originalBasket = [...basket]; - } + } }); after(function () { // runs once after the last test in this block - if(typeof basket === 'array') { + if (typeof basket === 'array') { basket = [...originalBasket]; - } + } }); describe('Created global variable for `basket` as empty array', function () { it('Created global variable for `basket` as empty array', function () { @@ -84,7 +84,7 @@ describe('Automated tests', function () { basket.length = 0; basket.push('Kale', 'Spinach'); let tempLog = console.log; - + // Temporarily override console.log console.log = (item) => result += item; listItems(basket); @@ -95,6 +95,7 @@ describe('Automated tests', function () { expect(result).to.be.a('string'); assert.equal(result.includes('Kale'), true); assert.equal(result.includes('Spinach'), true); + basket.length = 0; }); }); describe(`Functions are tested using console.log()`, function () {