Skip to content

Commit 7121063

Browse files
committed
refactor test to use JSON data instead of hard-coded string
1 parent 617f53c commit 7121063

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ try {
1414
}
1515

1616
let fs = require('fs');
17+
let quizData = require('../../quiz_data.json')
1718

1819
describe('Quiz Component', () => {
1920
it('renders a div with a className of `QuizQuestion` @quiz-component-has-quiz-question-div', () => {
@@ -23,25 +24,25 @@ describe('Quiz Component', () => {
2324
try {
2425
quiz = shallow(<Quiz />)
2526
} catch (e) {
26-
assert(false, "We weren't able to mount the Quiz component")
27+
assert(false, "We weren't able to mount the Quiz component.")
2728
}
2829

2930
if (quiz.containsMatchingElement(<div className="QuizQuestion"></div>)) {
3031
// this block will run after @quiz-component-has-quiz-question-div
31-
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`.")
3233
} else if ( quiz.find('.QuizQuestion').getElements().length == 1) {
3334
let el = quiz.find('.QuizQuestion').getElements()[0];
3435
if (el.props.className == 'QuizQuestion') {
3536
if (el.props.children == null) {
36-
assert(el.props.children == 'How many continents are there on Planet Earth?')
37+
assert(el.props.children == quizData.quiz_questions[0].instruction_text)
3738
}
3839
}
3940
} else if (quiz.find('QuizQuestion')) {
4041
} else if (quiz.containsMatchingElement(<div>Quiz</div>)) {
4142
// this block will run until @quiz-component-has-quiz-question-div
42-
assert(false, "The Quiz component isn't rendering a single div with the class `QuizQuestion`")
43+
assert(false, "The Quiz component isn't rendering a single div with the class `QuizQuestion`.")
4344
} else {
44-
assert(false, "The Quiz component isn't rendering a single div with the class `QuizQuestion`")
45+
assert(false, "The Quiz component isn't rendering a single div with the class `QuizQuestion`.")
4546
}
4647

4748
})

0 commit comments

Comments
 (0)