This are two examples of global helpers, which I'm using:
client/lib/helpers.js
Template.registerHelper('hasDocId', function() {
return !!FlowRouter.getParam('docId');
});
Template.registerHelper('epochToHuman', function(timestamp) {
let length;
timestamp = parseInt(timestamp);
if (timestamp)
length = timestamp.toString().length;
if (length === 13)
timestamp = timestamp / 1000;
if (length === 10 || length === 13)
return moment.unix(timestamp).format('MMMM Do, YYYY');
});
For testing with meteor (meteor test
) I created the file helpers.test.js
in the same directory:
client/lib/helpers.test.js
import { chai, expect } from 'meteor/practicalmeteor:chai';
import './helpers.js';
describe("The global helper", function () {
it("epochToHuman() should provide a date string", function () {
// SETUP
const timestamp = Math.floor(Date.now() / 1000);
// EXECUTE
const date = UI._globalHelpers.epochToHuman(timestamp);
// VERIFY
expect(date).to.be.a('string');
});
});
There are a few questions with that:
- I really have to explicitly import the files, which I want to test?
import './helpers.js';
- Is this test a proper way to check the helper? I don't think so, as it is just testing for a string...
- How do I do a test for the
hasDocId
helper as this is a FlowRouter helper?
Aucun commentaire:
Enregistrer un commentaire