Skip to content

Commit

Permalink
New immutability tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FriendlyUser1 committed Jul 22, 2024
1 parent c04e10a commit 43f1fcd
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions exercises/practice/lens-person/lens-person.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,36 @@ describe('nameLens', () => {
expect(nameLens.get(updatedPerson)).toEqual(updatedPerson.name);
});

xtest('should ensure immutability by checking the original person object', () => {
expect(person.name).toStrictEqual(new Name('Saravanan', 'Lakshmanan'));
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'),
);
expect(bornAtLens.get(updatedPerson)).toEqual(updatedPerson.born.bornAt);
});

xtest('should ensure immutability by checking the original person object', () => {
expect(person.born.bornAt).toStrictEqual(
new Address(100, 'Hospital street', 'Tamil Nadu', 'India'),
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);
});
});

Expand All @@ -68,7 +75,14 @@ describe('streetLens', () => {
expect(streetLens.get(updatedPerson)).toEqual(updatedPerson.address.street);
});

xtest('should ensure immutability by checking the original person object', () => {
expect(person.address.street).toStrictEqual('Coder street');
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);
});
});

0 comments on commit 43f1fcd

Please sign in to comment.