Learn Model Testing with TDD

Learn the skills to create the model layer of a web application using Mongoose and TDD.

Start[missing "en.views.course_landing_page.learn-testing-for-web-development.course_illustration" translation]
Chevron Left Icon
Mongoose Fundamentals
Lesson 1 of 2
Chevron Right Icon
  1. 1

    Mongoose is a Node package that interacts with a running MongoDB database. Before learning about Mongoose, let's define a couple of key terms: - Data - Database #### What is Data? Data in the...

  2. 2

    Mongo stores data in 'binary' JSON (BSON) documents. BSON documents have a similar structure to JavaScript objects. MongoDB stores documents in a collection. A MongoDB database is made up of t...

  3. 3

    Mongoose is a JavaScript library that provides methods to interact with a MongoDB database. Mongoose translates JavaScript objects (JSON) to BSON data in a MongoDB database, and vice versa. Mongoo...

  4. 4

    The key-value pair in a schema is called a path. Paths define the name and type of fields in a MongoDB document. [...] The schema above has three paths: [...] , [...] , and [...] . Each path...

  5. 5

    In our original poetry application example we declared the schema type for our [...] as a [...] : [...] Often, we want to specify more than just the type of a path — we can use _validat...

  6. 6

    To use our [...] definition: [...] we need to convert our [...] into a [...] we can work with. [...] provide the definition for a model. A model maps to a collection in your MongoDB data...

  7. 7

    Our model is a class with properties that we define in our schema. We can construct documents as instances of our model. Creating documents and saving them to the database can be done by calling [...

  8. 8

    At this point, we will start creating instances in a MongoDB database, then query the database for the values we saved. All of the method calls and queries will be passed to [...] . If we wante...

  9. 9

    Mongoose supports the creation of methods on both instances of documents and collections of documents (the model). - [...] adds static "class" methods to the model. - [...] adds an instance...

  10. 10

    In this lesson, you learned how to use Mongoose to interact with a MongoDB database. Let's review some of the topics that we covered: - Mongoose is a Node package that interacts with a running Mong...

  1. 1

    A chat app manages messages, users, and chat rooms. A restaurant app manages customers, tables, and orders. How do applications define these entities and their interactions? The answer is the *mod...

  2. 2

    In test-driving the zoo application, you receive this error message in the server layer: when the Dinosaur is valid   1) creates a new dinosaur with name 0 passing (47ms) 1...

  3. 3

    Before getting any further, let's recall some good TDD practices: - make your tests expressive by writing them in four phases - make your tests isolated with setup and teardown phases - follow...

  4. 4

    According to the Department of Dino Zoo Control (DDZC), the zoo isn't safe with more than 10 of any one type of Dinosaur. At this point your Dinosaur model has [...] , [...] , and [...] proper...

  5. 5

    Your test passes and the model technically satisfies the DDZC's no-more-than-10 regulation. But as it currently exists, there are two issues: - the validation error message is not helpful, and - th...

  6. 6

    Now that you've tested the persistence of data, you'll need methods to access that data. Mongoose schemas support - static methods: methods called by a model. They typically operate on a collect...

  7. 7

    Sometimes you need an instance method for your application, like if you see a server-level error such as this: GET  /breed/:name   1) increases count of named dinosaur 0 ...

  8. 8

    You have developed a model using TDD!

    • The model layer represents entities and interactions in a web app's problem domain.
    • Model paths can be test-driven using validators. Call [...] and ma...

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo

Learn Model Testing with TDD

Start[missing "en.views.course_landing_page.learn-testing-for-web-development.course_illustration" translation]