Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ assert(
`DisplayMessages` 組件的構造函數應調用 `super`,傳入 `props`。

```js
(getUserInput) =>
assert(
assert(
(function () {
const noWhiteSpace = __helpers.removeWhiteSpace(getUserInput('index'));
const noWhiteSpace = __helpers.removeWhiteSpace(code);
return (
noWhiteSpace.includes('constructor(props)') &&
noWhiteSpace.includes('super(props')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ Log the message `'Now I know React and Redux!'` to the console.
The message `Now I know React and Redux!` should be logged to the console.

```js
(getUserInput) =>
() =>
assert(
/console\s*\.\s*log\s*\(\s*('|"|`)Now I know React and Redux!\1\s*\)/.test(
getUserInput('index')
)
code)
);
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ assert(
`Provider` 組件應傳入相當於 Redux store 的 `store` 參數。

```js
(getUserInput) =>
() =>
assert(
(function () {
const mockedComponent = Enzyme.mount(React.createElement(AppWrapper));
return __helpers
.removeWhiteSpace(getUserInput('index'))
.removeWhiteSpace(code)
.includes('<Providerstore={store}>');
})()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ assert(
`Items` 組件應該有一個 `{ quantity: 10 }` 的 prop,該 prop 是從 `ShoppingCart` 組件傳遞過去的。

```js
(getUserInput) =>
() =>
assert(
(function () {
const mockedComponent = Enzyme.mount(React.createElement(ShoppingCart));
return (
mockedComponent.find('Items').props().quantity == 10 &&
getUserInput('index')
.replace(/ /g, '')
code.replace(/ /g, '')
.includes('<Itemsquantity={10}/>')
);
})()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ So far, you have been rendering React components on the client. Normally, this i
`App` 組件應該使用 `ReactDOMServer.renderToString` 渲染一個字符串。

```js
(getUserInput) =>
() =>
assert(
getUserInput('index')
.replace(/ /g, '')
code.replace(/ /g, '')
.includes('ReactDOMServer.renderToString(<App/>)') &&
Enzyme.mount(React.createElement(App)).children().name() === 'div'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ assert(
渲染的 `h1` 標籤應該包含 `{name}` 的引用。

```js
(getUserInput) =>
assert(/<h1>\n*\s*\{\s*name\s*\}\s*\n*<\/h1>/.test(getUserInput('index')));
assert(/<h1>\n*\s*\{\s*name\s*\}\s*\n*<\/h1>/.test(code));
```

渲染的 `h1` 標題元素應包含從組件狀態渲染的文本。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ async () => {
Render 方法中應該使用 `if/else` 語句來檢查 `this.state.display` 的條件。

```js
(getUserInput) =>
assert(
getUserInput('index').includes('if') &&
getUserInput('index').includes('else')
);
assert(code.includes('if') && code.includes('else'));
```

# --seed--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async () => {
render 方法應該使用 `&&` 邏輯運算符來檢查 `this.state.display` 的條件。

```js
(getUserInput) => assert(getUserInput('index').includes('&&'));
assert(code.includes('&&'));
```

# --seed--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,8 @@ assert(
`Items` 組件應該包含一個 `propTypes` 檢查,要求 `quantity` 有一個值,並且這個值的類型是 number。

```js
(getUserInput) =>
assert(
(function () {
const noWhiteSpace = __helpers.removeWhiteSpace(getUserInput('index'));
return (
noWhiteSpace.includes('quantity:PropTypes.number.isRequired') &&
noWhiteSpace.includes('Items.propTypes=')
);
})()
);
const noWhiteSpace = __helpers.removeWhiteSpace(code);
assert(noWhiteSpace.includes('quantity:PropTypes.number.isRequired') && noWhiteSpace.includes('Items.propTypes='));
```

# --seed--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ Now that you've learned the basics of JSX and React components, it's time to wri
應該有一個名爲 `MyComponent` 的 React 組件。

```js
(getUserInput) =>
assert(
__helpers
.removeWhiteSpace(getUserInput('index'))
.includes('classMyComponentextendsReact.Component{')
);
assert(__helpers.removeWhiteSpace(code).includes('classMyComponentextendsReact.Component{'));
```

`MyComponent` 應該包含一個 `h1` 標籤,標籤的文本爲 `My First React Component!`,區分大小寫並有標點符號。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ assert(
`rootReducer` 應該是一個合併了 `counterReducer` 和 `authReducer` 的函數。

```js
(getUserInput) =>
assert(
assert(
(function () {
const noWhiteSpace = __helpers.removeWhiteSpace(getUserInput('index'));
const noWhiteSpace = __helpers.removeWhiteSpace(code);
return (
typeof rootReducer === 'function' &&
noWhiteSpace.includes('Redux.combineReducers')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ assert(
`Object.assign` 應該被用於返回一個新狀態。

```js
(getUserInput) => assert(getUserInput('index').includes('Object.assign'));
assert(code.includes('Object.assign'));
```

# --seed--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ assert(store.getState().login === false);
`store.dispatch()` 方法應該被用於 dispatch 一個類型爲 `LOGIN` 的 action。

```js
(getUserInput) =>
assert(
assert(
(function () {
let noWhiteSpace = getUserInput('index').replace(/\s/g, '');
let noWhiteSpace = code.replace(/\s/g, '');
return (
noWhiteSpace.includes('store.dispatch(loginAction())') ||
noWhiteSpace.includes("store.dispatch({type: 'LOGIN'})") === true
);
})()
);
);
```

# --seed--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ assert(store.getState() === 5);
應該存在一個變量 `currentState`,併爲其分配 Redux store 的當前狀態。

```js
(getUserInput) =>
assert(
currentState === 5 && getUserInput('index').includes('store.getState()')
);
assert(currentState === 5 && code.includes('store.getState()'));
```

# --seed--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ assert(
`authReducer` 函數應該使用 `switch` 語句處理多個 action 類型。

```js
(getUserInput) =>
assert(
getUserInput('index').toString().includes('switch') &&
getUserInput('index').toString().includes('case') &&
getUserInput('index').toString().includes('default')
assert(
code.toString().includes('switch') &&
code.toString().includes('case') &&
code.toString().includes('default')
);
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ assert(
`authReducer` 函數應該使用 switch 語句處理多個 action 類型。

```js
(getUserInput) =>
assert(
assert(
(function () {
return (
typeof authReducer === 'function' &&
getUserInput('index').toString().includes('switch') &&
getUserInput('index').toString().includes('case') &&
getUserInput('index').toString().includes('default')
code.toString().includes('switch') &&
code.toString().includes('case') &&
code.toString().includes('default')
);
})()
);
Expand All @@ -94,11 +93,10 @@ assert(noWhiteSpace.includes('const'))
action creator 和 reducer 中應該引用 `LOGIN` 和 `LOGOUT` 常量。

```js
(getUserInput) =>
assert(
(function () {
const noWhiteSpace = __helpers.removeWhiteSpace(
getUserInput('index').toString()
code.toString()
);
return (
noWhiteSpace.includes('caseLOGIN:') &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ assert(
應使用擴展運算符返回新的 state。

```js
(getUserInput) => assert(getUserInput('index').includes('...state'));
assert(code.includes('...state'));
```

# --seed--
Expand Down
Loading