I'm trying to use nextjs within my app, was able to make it working with express as expected, but stuck with tests. How to test those app, which wrapped with nextjs?
server.js
const app = express();
nextApp.prepare()
.then(() => {
const userRoutes = require("./routes/userRoutes")(nextApp);
app.use("/", userRoutes);
app.get("testtest", (req, res) => {
const actualPage = '/index'
const query = { id: 'reqaramshhjjkkllvvoooo', test: 'testPropertyNN' }
nextApp.render(req, res, '/index', query);
})
const PORT = process.env.PORT || 5000;
server = await app.listen(PORT)
})
.catch((ex) => {
console.error(ex.stack)
process.exit(1)
})
module.exports = app;
and test it with this below, but receiving 404, how jest should be configured along with next what test would work? I'm just switching from create-react-app to nextjs but failing at test(without next managed it works), anyone has an example or any clue to get those work?
it('should get it workin', done => {
agent
.get(`/test`)
.end((err, res) => {
should.not.exist(err);
res.status.should.equal(200);
done();
})
})
Aucun commentaire:
Enregistrer un commentaire