chore(curriculum): prepare tests for recursion-protection (#46408)
* feat(client): add recursion protection to jsx * fix: change failed test for speed * fix: I guess this test was also changed for a reason * fix: change test to match babelification Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>pull/46958/head
parent
72a9e76ce5
commit
090a1caa7a
|
@ -39,15 +39,13 @@ assert(
|
|||
The `DisplayMessages` component should render a `div` containing an `h2` element, a `button` element, a `ul` element, and `li` elements as children.
|
||||
|
||||
```js
|
||||
async () => {
|
||||
() => {
|
||||
const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages));
|
||||
const waitForIt = (fn) =>
|
||||
new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100));
|
||||
const state = () => {
|
||||
mockedComponent.setState({ messages: ['__TEST__MESSAGE'] });
|
||||
return waitForIt(() => mockedComponent);
|
||||
return mockedComponent;
|
||||
};
|
||||
const updated = await state();
|
||||
const updated = state();
|
||||
assert(
|
||||
updated.find('div').length === 1 &&
|
||||
updated.find('h2').length === 1 &&
|
||||
|
@ -67,18 +65,16 @@ assert(code.match(/this\.state\.messages\.map/g));
|
|||
The `input` element should render the value of `input` in local state.
|
||||
|
||||
```js
|
||||
async () => {
|
||||
() => {
|
||||
const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages));
|
||||
const waitForIt = (fn) =>
|
||||
new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100));
|
||||
const causeChange = (c, v) =>
|
||||
c.find('input').simulate('change', { target: { value: v } });
|
||||
const testValue = '__TEST__EVENT__INPUT';
|
||||
const changed = () => {
|
||||
causeChange(mockedComponent, testValue);
|
||||
return waitForIt(() => mockedComponent);
|
||||
return mockedComponent;
|
||||
};
|
||||
const updated = await changed();
|
||||
const updated = changed();
|
||||
assert(updated.find('input').props().value === testValue);
|
||||
};
|
||||
```
|
||||
|
@ -86,19 +82,17 @@ async () => {
|
|||
Calling the method `handleChange` should update the `input` value in state to the current input.
|
||||
|
||||
```js
|
||||
async () => {
|
||||
() => {
|
||||
const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages));
|
||||
const waitForIt = (fn) =>
|
||||
new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100));
|
||||
const causeChange = (c, v) =>
|
||||
c.find('input').simulate('change', { target: { value: v } });
|
||||
const initialState = mockedComponent.state();
|
||||
const testMessage = '__TEST__EVENT__MESSAGE__';
|
||||
const changed = () => {
|
||||
causeChange(mockedComponent, testMessage);
|
||||
return waitForIt(() => mockedComponent);
|
||||
return mockedComponent;
|
||||
};
|
||||
const afterInput = await changed();
|
||||
const afterInput = changed();
|
||||
assert(
|
||||
initialState.input === '' &&
|
||||
afterInput.state().input === '__TEST__EVENT__MESSAGE__'
|
||||
|
@ -109,36 +103,34 @@ async () => {
|
|||
Clicking the `Add message` button should call the method `submitMessage` which should add the current `input` to the `messages` array in state.
|
||||
|
||||
```js
|
||||
async () => {
|
||||
() => {
|
||||
const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages));
|
||||
const waitForIt = (fn) =>
|
||||
new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100));
|
||||
const causeChange = (c, v) =>
|
||||
c.find('input').simulate('change', { target: { value: v } });
|
||||
const initialState = mockedComponent.state();
|
||||
const testMessage_1 = '__FIRST__MESSAGE__';
|
||||
const firstChange = () => {
|
||||
causeChange(mockedComponent, testMessage_1);
|
||||
return waitForIt(() => mockedComponent);
|
||||
return mockedComponent;
|
||||
};
|
||||
const firstResult = await firstChange();
|
||||
const firstResult = firstChange();
|
||||
const firstSubmit = () => {
|
||||
mockedComponent.find('button').simulate('click');
|
||||
return waitForIt(() => mockedComponent);
|
||||
return mockedComponent;
|
||||
};
|
||||
const afterSubmit_1 = await firstSubmit();
|
||||
const afterSubmit_1 = firstSubmit();
|
||||
const submitState_1 = afterSubmit_1.state();
|
||||
const testMessage_2 = '__SECOND__MESSAGE__';
|
||||
const secondChange = () => {
|
||||
causeChange(mockedComponent, testMessage_2);
|
||||
return waitForIt(() => mockedComponent);
|
||||
return mockedComponent;
|
||||
};
|
||||
const secondResult = await secondChange();
|
||||
const secondResult = secondChange();
|
||||
const secondSubmit = () => {
|
||||
mockedComponent.find('button').simulate('click');
|
||||
return waitForIt(() => mockedComponent);
|
||||
return mockedComponent;
|
||||
};
|
||||
const afterSubmit_2 = await secondSubmit();
|
||||
const afterSubmit_2 = secondSubmit();
|
||||
const submitState_2 = afterSubmit_2.state();
|
||||
assert(
|
||||
initialState.messages.length === 0 &&
|
||||
|
@ -152,25 +144,23 @@ async () => {
|
|||
The `submitMessage` method should clear the current input.
|
||||
|
||||
```js
|
||||
async () => {
|
||||
() => {
|
||||
const mockedComponent = Enzyme.mount(React.createElement(DisplayMessages));
|
||||
const waitForIt = (fn) =>
|
||||
new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 100));
|
||||
const causeChange = (c, v) =>
|
||||
c.find('input').simulate('change', { target: { value: v } });
|
||||
const initialState = mockedComponent.state();
|
||||
const testMessage = '__FIRST__MESSAGE__';
|
||||
const firstChange = () => {
|
||||
causeChange(mockedComponent, testMessage);
|
||||
return waitForIt(() => mockedComponent);
|
||||
return mockedComponent;
|
||||
};
|
||||
const firstResult = await firstChange();
|
||||
const firstResult = firstChange();
|
||||
const firstState = firstResult.state();
|
||||
const firstSubmit = () => {
|
||||
mockedComponent.find('button').simulate('click');
|
||||
return waitForIt(() => mockedComponent);
|
||||
return mockedComponent;
|
||||
};
|
||||
const afterSubmit = await firstSubmit();
|
||||
const afterSubmit = firstSubmit();
|
||||
const submitState = afterSubmit.state();
|
||||
assert(firstState.input === testMessage && submitState.input === '');
|
||||
};
|
||||
|
|
|
@ -161,7 +161,7 @@ Your code should not contain any `if/else` statements.
|
|||
```js
|
||||
assert(
|
||||
new RegExp(/(\s|;)if(\s|\()/).test(
|
||||
Enzyme.mount(React.createElement(CheckUserAge)).instance().render.toString()
|
||||
code
|
||||
) === false
|
||||
);
|
||||
```
|
||||
|
|
|
@ -26,13 +26,11 @@ while(i < 5) {
|
|||
See description above for instructions.
|
||||
|
||||
```js
|
||||
assert(
|
||||
assert.include(
|
||||
pick
|
||||
.toString()
|
||||
.replace(/\s/g, '')
|
||||
.includes(
|
||||
'while(numbers.length<10){if(_LPC++%2000===0&&Date.now()-_LP>1500){'
|
||||
)
|
||||
.replace(/\s/g, ''),
|
||||
'while(numbers.length<10){'
|
||||
);
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue