0

I am new to JS and I am trying to create a model with Mongoose but I get the following error: expected undefined to equal 'String' from the test system.

This is my code to create the model: `

// CREATE MODEL: Album
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const model = mongoose.model;

const albumSchema = new Schema({
  performer: {
    type: String, 
    required: true
  },
  title: {
    type: String,
    required: true
  },
  cost: {
    type: Number,
    required: true,
  },
});

const Album = model('Album', albumSchema)


// REMEMBER TO EXPORT YOUR MODEL:
module.exports = Album

`

This is the code of the tests:

    const createdModels = Object.keys(mongoose.models);

    describe('"Album" model', function () {
      it("should be declared", function () {
        expect(mongoose.models.Album).to.exist;
      });

      describe("should contain fields:", function () {
        const albumModel = mongoose.models.Album;
        const albumSchema = albumModel ? mongoose.models.Album.schema.obj : [];

        it("performer: String", function () {
          expect(albumSchema["performer"]).to.exist;
          expect(albumSchema["performer"].name).to.equal("String");
        });

        it("title: String", function () {
          expect(albumSchema["title"]).to.exist;
          expect(albumSchema["title"].name).to.equal("String");
        });

        it("cost: Number", function () {
          expect(albumSchema["cost"]).to.exist;
          expect(albumSchema["cost"].name).to.equal("Number");
        });
      });
    });
  • You haven't provided enough code to form a [mre]. You need to at least include how you are instantiating an instance of Album – Tibrogargan Nov 05 '22 at 08:59
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Nov 05 '22 at 09:54

0 Answers0