Model Testing with TDD 2 day struggle with error

I am in the Quote Keepers project in the TDD lesson plan here.

I hit a roadblock at step 7 where it says I should be error free, and in the green, when the test suite is run before refactoring. I still have an error.
I reset the project to square one and copied and pasted all of the provided code in the hints and it still doesn’t pass.

This is where I’m at now…

// test/models/quote-test.js
const Quote = require('../../models/quote');
const {assert} = require('chai');
const {mongoose, databaseUrl, options} = require('../../database');

describe('Quote', () => {
  beforeEach(async () => {
    await mongoose.connect(databaseUrl, options);
    await mongoose.connection.db.dropDatabase();

  afterEach(async () => {
    await mongoose.disconnect();

describe('#quote', () => {
  it('is a String', () => {
    const quoteAsInt = 1;

    const citation = new Quote({quote: quoteAsInt});
     assert.strictEqual(citation.quote, quoteAsInt.toString());

// database.js

const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
const env = process.env.NODE_ENV || 'development';
const databaseUrl = process.env.DATABASE_URL || `mongodb://localhost/quote-keeper_${env}`;
const options= {
  useMongoClient: true,

module.exports = {


// models/quote.js
const {mongoose} = require('../database');
const quoteSchema = new mongoose.Schema({
  quote: String
const Quote = mongoose.model('Quote', quoteSchema);

module.exports = Quote;


// test/routes/index-test.js
const {assert} = require('chai');
const request = require('supertest');
const {jsdom} = require('jsdom');
const Quote = require('../../models/quote');

const app = require('../../app');

const parseTextFromHTML = (htmlAsString, selector) => {
  const selectedElement = jsdom(htmlAsString).querySelector(selector);
  if (selectedElement !== null) {
    return selectedElement.textContent;
  } else {
    throw new Error(`No element with selector ${selector} found in HTML string`);

describe('/', () => {
  describe('POST', () => {
    it('responds with the quote', async () => {
      const quote = 'Our deepest fear is not that we are inadequate. Our deepest fear is that we are powerful beyond measure.';
      const attributed = 'Marianne Williamson';
      const source = 'A Return to Love: Reflections on the Principles of A Course in Miracles';

      const response = await request(app)
        .send({quote, attributed, source});

      assert.equal(response.status, 200);
      assert.include(parseTextFromHTML(response.text, '#quotes'), quote);
      assert.include(parseTextFromHTML(response.text, '#quotes'), attributed);
      assert.include(parseTextFromHTML(response.text, '#quotes'), source);

    it('stores the quote', async () => {
      const quote = 'Nothing is so painful to the human mind as a great and sudden change.';
      const attributed = 'Mary Shelley';
      const source = 'Frankenstein';

      const response = await request(app)
        .send({quote, attributed, source});

      const citation = await Quote.findOne({});
      assert.strictEqual(citation.quote, quote);
      assert.strictEqual(citation.attributed, attributed);
      assert.strictEqual(citation.source, source);

At first, the error was stated that Quote was undefined.
So, I added const Quote = require('../../models/quote'); to the index-test.js file (which wasn’t in the instructions, but figured it was something the lesson wanted me to figure out because Quote is referenced in that file)

Now, I am getting this error:

With a timeout error, I’m assuming that Mocha is waiting to make a connection. I’ve done everything it has asked for up to this point…
I have my beforeEach and afterEach hooks in place in quote-test.js.
It should be able to connect.

Any help would be appreciated.


Figured it out. The failure was supposed to be there. The instructions made it sound like there should be no errors at all showing up at this point. Just moving on made everything work.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.