I’ve wasted the morning trying to debug this one: the test suite keeps failing my second GET (/:artistsId) route and I can’t work out why! If someone could either point me in the right direction or point out the glaring syntax error that I’ve missed it would be hugely appreciated so I can crack on with this project:
Steps 13, 14, and 15 in the test suite are failing with this error message:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure “done()” is called; if returning a Promise, ensure it resolves.
Everything else seems to have worked up until this point, and if I run node server.js it executes with no errors.
Code in my artists.js file:
const express = require('express')
const sqlite3 = require('sqlite3')
const artistsRouter = express.Router()
const db = new sqlite3.Database(process.env.TEST_DATABASE || './database.sqlite')
artistsRouter.param('artistId', (req, res, next, artistId) => {
db.get(`SELECT * FROM Artist WHERE id = $artist_id`),
{$artist_id: artistId},
(err, artist) => {
if (err) {
next(err)
} else if (artist) {
req.artist = artist;
next()
} else {
res.status(404).send()
}
}
});
artistsRouter.get('/', (req, res, next) => {
db.all(`SELECT * FROM Artist WHERE is_currently_employed = 1`, (err, artists) => {
if (err) {
next(err)
} else {
res.status(200).json({artists: artists})
}
})
});
artistsRouter.get('/:artistId', (req, res, next) => {
res.status(200).json({artist: req.artist})
});
module.exports = artistsRouter
Thanks!