I'm making an app using Express and using Pug as the templating engine.
In my app.js file, I set a local variable like this: res.locals.user = req.user
Now, this local variable is available to all my views and I'm able to use user and it appears correctly when I run the app.
The problem happens when I try to run integration tests on my app. I always get a TypeError for all res.locals variables:
TypeError: /Users/dakshshah/Documents/Work/Git-Works/getfit/views/layout.pug:4
2| html
3| head
> 4| title= `${title} | ${h.siteName}`
5| link(rel='stylesheet', href='/dist/style.css')
6| link(rel="shortcut icon" type="image/png" href="/images/icons/favicon.png")
7| meta(name="viewport" content="width=device-width, initial-scale=1")
Cannot read property 'siteName' of undefined
.... error stack ....
Why are the res.locals variables not being passed to Pug during tests but work perfectly fine when using the app?
Aucun commentaire:
Enregistrer un commentaire