Can't load jade template for testing


#1

In my /imports/ui/admin/category folder, there are these files:

category.jade
category.js
category.test.js

As I want to do a test for the template helpers, I do get an error message

Error: Cannot find module './category.jade'

I don’t understand why, as this file exists and the app is working in non-test-mode. What am I doing wrong?

/imports/ui/admin/category/category.js

import { Categories } from '../../../api/collections.js';
import './category.jade';

Template.categories.helpers({
	categories() { 
		return Categories.find( { type: { $exists: false } } ); 
	}
});

Now I want to do a test for this helper:

/imports/ui/admin/category/category.test.js

import { chai, expect } from 'meteor/practicalmeteor:chai';
import './category.js';

describe("Category helper", function () {
	it("Should return a cursor to the template", function () {
		var categories = Template.categories.__helpers.get('categories');
		expect(categories).to.not.be.undefined;

	});
});

/imports/ui/ui.js

import './admin/category/category.js';

Which is loaded by…

/client/main.js

import '/imports/ui/ui.js';

#2

Just any idea for what I can look? I’m really stucked on that…


#3

A few things that might help:

  • Since you’re testing the UI you might want to move your category.test.js file under a client directory (or wrapping it in a Meteor.isClient check), something like /imports/ui/admin/category/client/category.test.js. This will prevent the test from being run on the server.
  • You’re referencing Template in your test but haven’t brought it in via an import. You’ll likely want to add:
import { Template } from 'meteor/templating';

#4

Thanks for your reply. Didn’t think of the fact to keep this test on client.