From 2efaed2c590bc4c3b76ad6d3a617f93a07d57ec5 Mon Sep 17 00:00:00 2001 From: ciiro Date: Wed, 24 Jul 2024 13:03:02 +0100 Subject: [PATCH] [Lens Person] Fix typos and immutability tests (#2509) * Fix typos and immutability tests * New immutability tests --- exercises/practice/lens-person/lens-person.js | 2 +- .../practice/lens-person/lens-person.spec.js | 52 ++++++++----------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/exercises/practice/lens-person/lens-person.js b/exercises/practice/lens-person/lens-person.js index 2a07feb382..97d885c21a 100644 --- a/exercises/practice/lens-person/lens-person.js +++ b/exercises/practice/lens-person/lens-person.js @@ -1,5 +1,5 @@ // -// This is only a SKELETON file for the 'Lense Person' exercise. It's been provided as a +// This is only a SKELETON file for the 'Lens Person' exercise. It's been provided as a // convenience to get you started writing code faster. // diff --git a/exercises/practice/lens-person/lens-person.spec.js b/exercises/practice/lens-person/lens-person.spec.js index 8f41e27fa1..b14b8e5a8f 100644 --- a/exercises/practice/lens-person/lens-person.spec.js +++ b/exercises/practice/lens-person/lens-person.spec.js @@ -7,7 +7,7 @@ import { bornAtLens, nameLens, streetLens } from './lens-person'; // test data const person = new Person( - new Name('Saravanan', 'Lakshamanan'), + new Name('Saravanan', 'Lakshmanan'), new Born( new Address(100, 'Hospital street', 'Tamil Nadu', 'India'), new Date(), @@ -31,20 +31,20 @@ describe('nameLens', () => { expect(nameLens.get(updatedPerson)).toEqual(updatedPerson.name); }); - xtest('should ensure immutability by checking the original person object', () => { - expect(person).not.toStrictEqual( - new Person(new Name('Sara', 'Lakshamanan'), person.born, person.address), - ); + xtest('should ensure immutability when setting a new name', () => { + const originalName = new Name('Saravanan', 'Lakshmanan'); + nameLens.set(person, new Name('Subhash', 'Forst')); + expect(person.name).toStrictEqual(originalName); }); }); // Test suite for bornAtLens describe('bornAtLens', () => { - xtest('should get the address where the person was born', () => { + xtest('should get the address for where the person was born', () => { expect(bornAtLens.get(person)).toEqual(person.born.bornAt); }); - xtest('should set a new street for the place where the person was born', () => { + xtest('should set a new address for where the person was born', () => { const updatedPerson = bornAtLens.set( person, new Address(2, 'Exercism street', 'Tamil Nadu', 'India'), @@ -52,17 +52,15 @@ describe('bornAtLens', () => { expect(bornAtLens.get(updatedPerson)).toEqual(updatedPerson.born.bornAt); }); - xtest('should ensure immutability by checking the original person object', () => { - expect(person).not.toEqual( - new Person( - person.name, - new Born( - new Address(2, 'Exercism street', 'Tamil Nadu', 'India'), - person.born.bornOn, - ), - person.address, - ), + xtest('should ensure immutability when setting a new birth address', () => { + const originalBirthAddress = new Address( + 100, + 'Hospital street', + 'Tamil Nadu', + 'India', ); + bornAtLens.set(person, new Address(15, 'Clinic street', 'Kerala', 'India')); + expect(person.born.bornAt).toStrictEqual(originalBirthAddress); }); }); @@ -77,18 +75,14 @@ describe('streetLens', () => { expect(streetLens.get(updatedPerson)).toEqual(updatedPerson.address.street); }); - xtest('should ensure immutability by checking the original person object', () => { - expect(person).not.toEqual( - new Person( - person.name, - person.born, - new Address( - person.address.houseNumber, - 'Exercism Street', - person.address.place, - person.address.country, - ), - ), + xtest('should ensure immutability when setting a new street', () => { + const originalAddress = new Address( + 1, + 'Coder street', + 'Tamil Nadu', + 'India', ); + streetLens.set(person, 'Mimic street'); + expect(person.address).toStrictEqual(originalAddress); }); });