Facing issue while writing test case for `at-form`


#1

Hi,

I have a Meteor project using BlazeJS. I am writing test case for that project in Mocha for rendering. And i am facing below issue:-

  1. I have an at-form form both SignIn and SignUp and configure both templates like below.
AccountsTemplates.addFields([
  {
    _id: 'username',
    type: 'text',
    displayName: 'username',
    required: true,
    minLength: 5,
  },
  {
    _id: 'email',
    type: 'email',
    required: true,
    displayName: 'email',
    re: /.+@(.+){2,}\.(.+){2,}/,
    errStr: 'Invalid email',
  },
  {
    _id: 'username_and_email',
    type: 'text',
    required: true,
    displayName: 'Login',
    placeholder: 'Username or Email',
  },
  passwordField,
]);

// Sign in
AccountsTemplates.configureRoute('signIn', {
  layoutType: 'blaze',
  name: 'signIn',
  path: '/sign-in',
  layoutTemplate: 'masterLayout',
  contentRegion: 'main',
});

// Sign up
AccountsTemplates.configureRoute('signUp', {
  layoutType: 'blaze',
  name: 'signUp',
  path: '/sign-up',
  layoutTemplate: 'masterLayout',
  contentRegion: 'main',
});

  1. I have write test case for rendering of SignUp page but not getting template.
const withDiv = function withDiv(callback) {
  const el = document.createElement('div');
  document.body.appendChild(el);
  try {
    callback(el);
  } finally {
    document.body.removeChild(el);
  }
};

export const withRenderedTemplate = function withRenderedTemplate(template, data, callback) {
  withDiv((el) => {
    const ourTemplate = _.isString(template) ? Template[template] : template;
    // console.log(_.isString(template),": template - ",Template[template],": data - ",data);
    // console.log(":: el - ",el);
    Blaze.renderWithData(ourTemplate, data, el);
    Tracker.flush();
    callback(el);
  });
};


if (Meteor.isClient) {
  import { AccountsTemplates } from 'meteor/useraccounts:core';
  describe('SignUp Page Rendering', function() {
      it ('check render of SignUp page', function() {
        const item = BlazeLayout.render('masterLayout', { main: 'signUp' });
        const data = {my:"MY"};
        withRenderedTemplate('signUp', data, (el) => {
          console.log(':: el ',el)
          console.log(':: ("#at-field-username").length ',$(el).find('#at-field-username').length)
          chai.assert.equal($(el).find('#at-field-username').length, 1);
        });
      })
  });
}

I am getting Template[template] as undefined.

Please advise how i resolved above issue.

Thanks & Regards,
Saransh