Testing handlebars file with mocha in express issue

Testing handlebars file with mocha in express issue


I want to Mocha test to apply to only one local file about.handlebars. Here is my project structure:

app root

When I add
var about = require('./views/about.handlebars');
I receive an error:
Error: Cannot find module './views/about.handlebars’
When I use
import {about} from './views/about.handlebars';

I get another error message
SyntaxError: Unexpected token import

Does anyone worked with Mocha and encountered similar problems? Any help is very much appreciated!


Is this what you are trying to do?
Maybe handlebars needs to be compiled?

Or this script for compiling Handlebars?


The line of code is from main_test.js?


You need two dots to get to the previous directory.

var about = require('../views/about.handlebars');


Yes, it is from test.js


Thank you everyone for your answers! There was indeed a problem with a path and handlebars needed to be compiled too. I made the corrections and now it works!

var fs = require('fs');
var handlebars = require('handlebars');

require.extensions['.hbs'] = function (module, filename) {
   module.exports = handlebars.compile;
		var raw = fs.readFileSync(filename).toString();

var assert = require('chai').assert;
var about = require('../views/about.handlebars');