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");
});
});
});