In test-driving the zoo application, you receive this error message in the server layer:

ReferenceError: Dinosaur is not defined

You’re in the red! To get to green you have to drop to the model layer and define the Dinosaur model.

You’ll need multiple model tests to satisfy this server test. Since they don’t touch HTML/CSS selectors nor HTTP actions/status codes, model tests are typically faster than feature-level and server-level tests. Driving the Dinosaur implementation with model tests — rather than feature or server tests — will make your test suite run faster. The model tests will confirm that:

  1. the Dinosaur model is defined
  2. the Dinosaur model has a path called name

Your first test will cover conditions 1 and 2 by creating an instance of a Dinosaur model with a name, then asserting that the name path (also referred to as field or property) can be retrieved.

You can review the Mongoose guide for defining a schema and the model documentation for creating models and instances.



Write your first model test! In dinosaur-test.js under it('is a String', construct a new instance of the Dinosaur model. Use the constructor new Dinosaur() and store the result in a variable dino.


Run the test and see the error message

ReferenceError: DinosaurSchema is not defined

The error directs you to define a Dinosaur schema. In dinosaur.js define a Dinosaur schema named DinosaurSchema without any paths. Use the constructor new Schema().


Run the test and see green!


But the test doesn’t check the name path. In dinosaur-test.js within the Dinosaur constructor, add a name path with value 'T-rex'.

Don’t forget to use braces { }.


Assert that the name of the dino is strictly equal to 'T-rex'.

Use Chai’s assert.strictEqual(actual, expected) method.


Run the test and see the error message

AssertionError: expected undefined to equal 'T-rex'

The error directs you to define a name path. In dinosaur.js define a name path in the Schema constructor of type String.

Don’t forget to use braces { }.


Run the test and see green!

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?