Skip to content

Train Driver: Prevent deleting object property #2674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions exercises/concept/train-driver/train-driver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ function list(...values) {
return new LimitedArray(values);
}

function time(timeOfArrival, route) {
Object.defineProperty(route, 'timeOfArrival', {
configurable: false,
writable: false,
enumerable: true,
value: timeOfArrival,
});

return route;
}

describe('getListOfWagons', () => {
test('returns the correct array', () => {
expect(getListOfWagons(1, 5, 2, 7, 4)).toEqual([1, 5, 2, 7, 4]);
Expand Down Expand Up @@ -181,13 +192,12 @@ describe('extendRouteInformation', () => {

describe('separateTimeOfArrival', () => {
test('separates timeOfArrival from complete object', () => {
const route = {
const route = time('12:00', {
from: 'Berlin',
to: 'Hamburg',
timeOfArrival: '12:00',
precipitation: '10',
temperature: '5',
};
});

const expected = [
'12:00',
Expand All @@ -198,12 +208,11 @@ describe('separateTimeOfArrival', () => {
});

test('separates timeOfArrival with smaller object', () => {
const route = {
const route = time('10:30', {
from: 'Paris',
to: 'London',
timeOfArrival: '10:30',
temperature: '20',
};
});

const expected = [
'10:30',
Expand All @@ -214,13 +223,12 @@ describe('separateTimeOfArrival', () => {
});

test('separates timeOfArrival from differently ordered object', () => {
const route = {
const route = time('21:20', {
from: 'Gothenburg',
to: 'Copenhagen',
precipitation: '1',
timeOfArrival: '21:20',
temperature: '-6',
};
});

const expected = [
'21:20',
Expand Down