mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-30 16:01:14 -04:00
refactor: remove DeepEqual (#59569)
This commit is contained in:
committed by
GitHub
parent
fb10a28554
commit
3f3b1b4b9c
@@ -25,18 +25,14 @@ The Redux state and actions were modified to handle an `object` for the `state`.
|
||||
The Redux store should exist and initialize with a state that is equivalent to the `defaultState` object declared on line 1.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
const expectedState = {
|
||||
user: 'CamperBot',
|
||||
status: 'offline',
|
||||
friends: '732,982',
|
||||
community: 'freeCodeCamp'
|
||||
};
|
||||
const initialState = store.getState();
|
||||
return DeepEqual(expectedState, initialState);
|
||||
})()
|
||||
);
|
||||
const expectedState = {
|
||||
user: 'CamperBot',
|
||||
status: 'offline',
|
||||
friends: '732,982',
|
||||
community: 'freeCodeCamp'
|
||||
};
|
||||
const initialState = store.getState();
|
||||
assert.deepEqual(expectedState, initialState);
|
||||
```
|
||||
|
||||
`wakeUp` and `immutableReducer` both should be functions.
|
||||
@@ -48,21 +44,19 @@ assert(typeof wakeUp === 'function' && typeof immutableReducer === 'function');
|
||||
Dispatching an action of type `ONLINE` should update the property `status` in state to `online` and should NOT mutate state.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
const initialState = store.getState();
|
||||
const isFrozen = DeepFreeze(initialState);
|
||||
store.dispatch({ type: 'ONLINE' });
|
||||
const finalState = store.getState();
|
||||
const expectedState = {
|
||||
user: 'CamperBot',
|
||||
status: 'online',
|
||||
friends: '732,982',
|
||||
community: 'freeCodeCamp'
|
||||
};
|
||||
return isFrozen && DeepEqual(finalState, expectedState);
|
||||
})()
|
||||
);
|
||||
|
||||
const initialState = store.getState();
|
||||
const isFrozen = !!DeepFreeze(initialState);
|
||||
store.dispatch({ type: 'ONLINE' });
|
||||
const finalState = store.getState();
|
||||
const expectedState = {
|
||||
user: 'CamperBot',
|
||||
status: 'online',
|
||||
friends: '732,982',
|
||||
community: 'freeCodeCamp'
|
||||
};
|
||||
assert(isFrozen);
|
||||
assert.deepEqual(finalState, expectedState);
|
||||
```
|
||||
|
||||
`Object.assign` should be used to return new state.
|
||||
|
||||
@@ -48,22 +48,19 @@ assert(typeof addToDo === 'function' && typeof immutableReducer === 'function');
|
||||
Dispatching an action of type `ADD_TO_DO` on the Redux store should add a `todo` item and should NOT mutate state.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
const initialState = store.getState();
|
||||
const isFrozen = DeepFreeze(initialState);
|
||||
store.dispatch(addToDo('__TEST__TO__DO__'));
|
||||
const finalState = store.getState();
|
||||
const expectedState = [
|
||||
'Go to the store',
|
||||
'Clean the house',
|
||||
'Cook dinner',
|
||||
'Learn to code',
|
||||
'__TEST__TO__DO__'
|
||||
];
|
||||
return isFrozen && DeepEqual(finalState, expectedState);
|
||||
})()
|
||||
);
|
||||
const initialState = store.getState();
|
||||
const isFrozen = !!DeepFreeze(initialState);
|
||||
store.dispatch(addToDo('__TEST__TO__DO__'));
|
||||
const finalState = store.getState();
|
||||
const expectedState = [
|
||||
'Go to the store',
|
||||
'Clean the house',
|
||||
'Cook dinner',
|
||||
'Learn to code',
|
||||
'__TEST__TO__DO__'
|
||||
];
|
||||
assert(isFrozen);
|
||||
assert.deepEqual(finalState, expectedState);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
@@ -19,15 +19,9 @@ The reducer and action creator were modified to remove an item from an array bas
|
||||
The Redux store should exist and initialize with a state equal to `[0,1,2,3,4,5]`
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
const initialState = store.getState();
|
||||
return (
|
||||
Array.isArray(initialState) === true &&
|
||||
DeepEqual(initialState, [0, 1, 2, 3, 4, 5])
|
||||
);
|
||||
})()
|
||||
);
|
||||
const initialState = store.getState();
|
||||
assert.isArray(initialState)
|
||||
assert.deepEqual(initialState, [0, 1, 2, 3, 4, 5])
|
||||
```
|
||||
|
||||
`removeItem` and `immutableReducer` both should be functions.
|
||||
@@ -41,26 +35,22 @@ assert(
|
||||
Dispatching the `removeItem` action creator should remove items from the state and should NOT mutate state.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
const initialState = store.getState();
|
||||
const isFrozen = DeepFreeze(initialState);
|
||||
store.dispatch(removeItem(3));
|
||||
const state_1 = store.getState();
|
||||
store.dispatch(removeItem(2));
|
||||
const state_2 = store.getState();
|
||||
store.dispatch(removeItem(0));
|
||||
store.dispatch(removeItem(0));
|
||||
store.dispatch(removeItem(0));
|
||||
const state_3 = store.getState();
|
||||
return (
|
||||
isFrozen &&
|
||||
DeepEqual(state_1, [0, 1, 2, 4, 5]) &&
|
||||
DeepEqual(state_2, [0, 1, 4, 5]) &&
|
||||
DeepEqual(state_3, [5])
|
||||
);
|
||||
})()
|
||||
);
|
||||
const initialState = store.getState();
|
||||
const isFrozen = !!DeepFreeze(initialState);
|
||||
store.dispatch(removeItem(3));
|
||||
const state_1 = store.getState();
|
||||
store.dispatch(removeItem(2));
|
||||
const state_2 = store.getState();
|
||||
store.dispatch(removeItem(0));
|
||||
store.dispatch(removeItem(0));
|
||||
store.dispatch(removeItem(0));
|
||||
const state_3 = store.getState();
|
||||
|
||||
assert(isFrozen)
|
||||
assert.deepEqual(state_1, [0, 1, 2, 4, 5])
|
||||
assert.deepEqual(state_2, [0, 1, 4, 5])
|
||||
assert.deepEqual(state_3, [5])
|
||||
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
@@ -45,16 +45,13 @@ assert(typeof addToDo === 'function' && typeof immutableReducer === 'function');
|
||||
Dispatching an action of type `ADD_TO_DO` on the Redux store should add a `todo` item and should NOT mutate state.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
const initialState = store.getState();
|
||||
const isFrozen = DeepFreeze(initialState);
|
||||
store.dispatch(addToDo('__TEST__TO__DO__'));
|
||||
const finalState = store.getState();
|
||||
const expectedState = ['Do not mutate state!', '__TEST__TO__DO__'];
|
||||
return isFrozen && DeepEqual(finalState, expectedState);
|
||||
})()
|
||||
);
|
||||
const initialState = store.getState();
|
||||
const isFrozen = !!DeepFreeze(initialState);
|
||||
store.dispatch(addToDo('__TEST__TO__DO__'));
|
||||
const finalState = store.getState();
|
||||
const expectedState = ['Do not mutate state!', '__TEST__TO__DO__'];
|
||||
assert(isFrozen)
|
||||
assert.deepEqual(finalState, expectedState);
|
||||
```
|
||||
|
||||
The spread operator should be used to return new state.
|
||||
|
||||
@@ -28,22 +28,17 @@ assert(
|
||||
Your `difference` method should return the proper collection.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
var setA = new Set();
|
||||
var setB = new Set();
|
||||
setA.add('a');
|
||||
setA.add('b');
|
||||
setA.add('c');
|
||||
setB.add('c');
|
||||
setB.add('d');
|
||||
var differenceSetAB = setA.difference(setB);
|
||||
return (
|
||||
differenceSetAB.size() === 2 &&
|
||||
DeepEqual(differenceSetAB.values(), ['a', 'b'])
|
||||
);
|
||||
})()
|
||||
);
|
||||
var setA = new Set();
|
||||
var setB = new Set();
|
||||
setA.add('a');
|
||||
setA.add('b');
|
||||
setA.add('c');
|
||||
setB.add('c');
|
||||
setB.add('d');
|
||||
var differenceSetAB = setA.difference(setB);
|
||||
|
||||
assert.equal(differenceSetAB.size(), 2)
|
||||
assert.deepEqual(differenceSetAB.values(), ['a', 'b'])
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
@@ -37,12 +37,8 @@ In this exercise we will pass an array and a value to the checkSet() function. Y
|
||||
`checkSet([4, 5, 6], 3)` should return [ false, 3 ]
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
var test = checkSet([4, 5, 6], 3);
|
||||
return DeepEqual(test, [false, 3]);
|
||||
})()
|
||||
);
|
||||
var test = checkSet([4, 5, 6], 3);
|
||||
assert.deepEqual(test, [false, 3]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
@@ -31,12 +31,8 @@ Now you've successfully learned how to use the ES6 `Set()` object, good job!
|
||||
`checkSet(new Set([1,2,3,4,5,6,7])` should return `[1, 2, 3, 4, 5, 6, 7]`.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(function () {
|
||||
var test = checkSet(new Set([1, 2, 3, 4, 5, 6, 7]));
|
||||
return DeepEqual(test, [1, 2, 3, 4, 5, 6, 7]);
|
||||
})()
|
||||
);
|
||||
var test = checkSet(new Set([1, 2, 3, 4, 5, 6, 7]));
|
||||
assert.deepEqual(test, [1, 2, 3, 4, 5, 6, 7]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
@@ -27,10 +27,6 @@ async function initTestFrame(e: InitTestFrameArg = { code: {} }) {
|
||||
};
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
// Fake Deep Equal dependency
|
||||
const DeepEqual = (a: Record<string, unknown>, b: Record<string, unknown>) =>
|
||||
JSON.stringify(a) === JSON.stringify(b);
|
||||
|
||||
// Hardcode Deep Freeze dependency
|
||||
const DeepFreeze = (o: Record<string, unknown>) => {
|
||||
Object.freeze(o);
|
||||
|
||||
@@ -80,11 +80,6 @@ const __utils = (() => {
|
||||
};
|
||||
})();
|
||||
|
||||
// Fake Deep Equal dependency
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const DeepEqual = (a: unknown, b: unknown) =>
|
||||
JSON.stringify(a) === JSON.stringify(b);
|
||||
|
||||
// We can't simply import these because of how webpack names them when building
|
||||
// the bundle. Since both assert and __helpers have to exist in the global
|
||||
// scope, we have to declare them.
|
||||
|
||||
Reference in New Issue
Block a user