Skip to content

Commit f02ffbb

Browse files
committed
update tests
1 parent 2f38957 commit f02ffbb

8 files changed

Lines changed: 22 additions & 15 deletions

‎src/__tests__/part2/quiz-component-displays-instruction-text.test.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ describe('Quiz Component', () => {
2828
}
2929

3030
if (quiz.find('.QuizQuestion').length > 0) {
31-
assert(quiz.find('.QuizQuestion').text() == quiz_data.quiz_questions[0].instruction_text, "The div with a class of `QuizQuestion` isn't displaying the correct instruction text.")
32-
} else if (quiz.find('QuizQuestion')) {
33-
// this block will run after @quiz-component-displays-quiz-question-component
31+
assert(quiz.find('.QuizQuestion').text() == quiz_data.quiz_questions[0].instruction_text, "The div with a className of `QuizQuestion` isn't displaying the correct instruction text.")
3432
} else {
3533
assert(false, "There is not a div with a className of QuizQuestion yet.")
3634
}

‎src/__tests__/part2/quiz-component-has-quiz-question-div.test.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('Quiz Component', () => {
2929

3030
if (quiz.containsMatchingElement(<div className="QuizQuestion"></div>)) {
3131
// this block will run after @quiz-component-has-quiz-question-div
32-
assert(quiz.containsMatchingElement(<div className="QuizQuestion"></div>), "The Quiz component isn't rendering a single div with the class `QuizQuestion`")
32+
assert(quiz.containsMatchingElement(<div className="QuizQuestion"></div>), "The Quiz component isn't rendering a single div with the class `QuizQuestion`")
3333
} else if ( quiz.find('.QuizQuestion').getElements().length == 1) {
3434
let el = quiz.find('.QuizQuestion').getElements()[0];
3535
if (el.props.className == 'QuizQuestion') {
@@ -40,8 +40,6 @@ describe('Quiz Component', () => {
4040
} else if (quiz.containsMatchingElement(<div>Quiz</div>)) {
4141
// this block will run until @quiz-component-has-quiz-question-div
4242
assert(false, "The Quiz component isn't rendering a single div with the class `QuizQuestion`")
43-
} else if (quiz.find('QuizQuestion')) {
44-
// this block will run after @quiz-component-displays-quiz-question-component
4543
} else {
4644
assert(false, "The Quiz component isn't rendering a single div with the class `QuizQuestion`")
4745
}

‎src/__tests__/part3/quiz-question-component-has-quiz-question-prop.test.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('Quiz Component', () => {
3838
}
3939

4040
assert(quiz.find('QuizQuestion').length == 1, "We couldn't find the QuizQuestion component being loaded by the Quiz component")
41-
assert(quiz.find('QuizQuestion').props().quiz_question != null, "prop doesn't exist")
42-
assert(quiz.find('QuizQuestion').props().quiz_question == quiz_data.quiz_questions[0], "prop doesn't have the correct value")
41+
assert(quiz.find('QuizQuestion').props().quiz_question != null, "The QuizQuestion component exists, but there's no prop named `quiz_question`.")
42+
assert(quiz.find('QuizQuestion').props().quiz_question == quiz_data.quiz_questions[0], "The QuizQuestion component has a prop named `quiz_question`, but it doesn't contain the correct value.")
4343
})
4444
})

‎src/__tests__/part4/quiz-question-button-component-has-button-text-prop.test.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ describe('QuizQuestion Component', () => {
4747
button_text: '5'
4848
}
4949
if (quizQuestion.find('QuizQuestionButton').length == 1) {
50-
assert(JSON.stringify(quizQuestion.find('QuizQuestionButton').props()) == JSON.stringify(expectedProps), "You're not passing the correct prop values to QuizQuestionButton")
50+
assert(JSON.stringify(quizQuestion.find('QuizQuestionButton').props()) == JSON.stringify(expectedProps), "You're not passing the correct prop values to QuizQuestionButton.")
5151
} else {
52-
// this will run after @quiz-question-component-maps-multiple-button-components
52+
assert(false, "We don't see the QuizQuestionButton element in the QuizQuestion component's JSX.")
5353
}
5454

5555
})

‎src/__tests__/part6/quiz-handle-click-increments-position-state.test.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ describe('Quiz Component', () => {
3232

3333
if (quiz.state().quiz_position) {
3434
assert(quiz.state().quiz_position == quiz_data.quiz_position, "The Quiz component's state does not have a key named `quiz_position` with the correct value - are you sure you're still setting the component's state to `quiz_data`?")
35-
quiz.instance().handleClick()
36-
assert(quiz.state().quiz_position == quiz_data.quiz_position+1, "The Quiz component state's `quiz_position` value is not being incremented by 1 when the `handleClick()` method is called.")
35+
try {
36+
quiz.instance().handleClick()
37+
} catch (e) {
38+
assert(false, "There's not a method named `handleClick()` in the Quiz class.")
39+
}
40+
41+
assert(quiz.state().quiz_position == quiz_data.quiz_position + 1, "The Quiz component state's `quiz_position` value is not being incremented by 1 when the `handleClick()` method is called.")
3742
}
3843
})
3944
})

‎src/__tests__/part6/quiz-question-handle-click-method-returns-correct-value.test.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ describe('QuizQuestion Component', () => {
7979
assert(spy2.called == false, "It doesn't appear that the conditional logic checking if the `buttonText` is equal to `this.props.quiz_question.answer` in the QuizQuestion's `handleClick` method.")
8080
try {
8181
quizQuestion.instance().handleClick('5')
82-
assert(spy2.called == true, "`this.props.clickHandler()` is not being called when the `buttonText` is equal to `this.props.quiz_question.answer` in QuizQuestion's `handleClick` method.")
8382
} catch (e) {
84-
8583
}
84+
assert(spy2.called == true, "`this.props.clickHandler()` is not being called when the `buttonText` is equal to `this.props.quiz_question.answer` in QuizQuestion's `handleClick` method.")
8685
})
8786
})

‎src/__tests__/part7/quiz-question-component-shows-error-tag.test.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ describe('QuizQuestion Component', () => {
3636
incorrectAnswer: false
3737
}
3838

39+
assert(quizQuestion.state() != null, "The QuizQuestion component isn't starting with the correct default state declared in the constructor function.")
40+
3941
assert(quizQuestion.state().incorrectAnswer != null && quizQuestion.state().incorrectAnswer == false, "The QuizQuestion component's state should start out with a key of `incorrectAnswer` set to `false`.")
4042

4143
quizQuestion.setState({ incorrectAnswer: true })

‎src/__tests__/part8/quiz-handle-reset-click-sets-position-state.test.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ describe('Quiz Component', () => {
3333
quiz.setState({ quiz_position: 3 })
3434

3535
assert(quiz.state().quiz_position == 3, "The Quiz component's state does not have a key named `quiz_position` with the correct value - are you sure you're still setting the component's state to `quiz_data`?")
36-
quiz.instance().handleResetClick()
36+
37+
try {
38+
quiz.instance().handleResetClick()
39+
} catch (e) {
40+
assert(false, "There's not a method named `handleResetClick()` in the Quiz class.")
41+
}
3742

3843
assert(quiz.state().quiz_position == 1, "The Quiz component state's `quiz_position` value is not being reset to 1 when the `handleResetClick()` method is called.")
3944
})

0 commit comments

Comments
 (0)