0
0
Expressframework~10 mins

Test database setup and teardown in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Express module.

Express
const express = require([1]);
Drag options to blanks, or click blank then click option'
A"express"
B"http"
C"path"
D"fs"
Attempts:
3 left
💡 Hint
Common Mistakes
Using other module names like 'http' or 'fs' instead of 'express'.
Forgetting the quotes around the module name.
2fill in blank
medium

Complete the code to create a new Express application instance.

Express
const app = [1]();
Drag options to blanks, or click blank then click option'
Arouter
Bhttp
Cexpress
Dserver
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' or 'server' instead of 'express'.
Forgetting the parentheses after the function name.
3fill in blank
hard

Fix the error in the test setup function to connect to the test database.

Express
beforeAll(async () => {
  await [1].connect('mongodb://localhost/testdb');
});
Drag options to blanks, or click blank then click option'
Ahttp
Bmongoose
Cexpress
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to connect using 'app' or 'express' which are for the server.
Using 'http' which is unrelated to database connections.
4fill in blank
hard

Fill both blanks to properly close the database connection after tests.

Express
afterAll(async () => {
  await [1].[2]();
});
Drag options to blanks, or click blank then click option'
Amongoose
Bapp
Cdisconnect
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app.close()' which closes the server, not the database.
Using 'mongoose.close()' which is not a valid method.
5fill in blank
hard

Fill all three blanks to set up and tear down a test database connection correctly.

Express
beforeAll(async () => {
  await [1].connect('mongodb://localhost/testdb');
});

afterAll(async () => {
  await [2].[3]();
});
Drag options to blanks, or click blank then click option'
Amongoose
Bapp
Cdisconnect
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app' instead of 'mongoose' for database operations.
Using 'close' instead of 'disconnect' to close the database.