時計モードでpracticalmeteor:mocha
を使用していて、UIテスト(ユニットテストのテンプレートコンポーネント)を記述しました。Meteor mocha watchモードでは、アサーションメッセージの代わりにコード行を表示します
失敗したテストではアサーションメッセージが表示されず、代わりにコードスニペットが表示されるという奇妙な問題があります。
Iは、例えば、出力した画像を添付しています
残念ながら、私はパッケージやモカ自体のドキュメントでこれに関連する構成に関する情報を見つけることができませんでした。
// PACKAGES
import {Meteor} from 'meteor/meteor';
import {Template} from 'meteor/templating';
import {$} from 'meteor/jquery';
import {Random} from 'meteor/random';
import {chai, assert} from 'meteor/practicalmeteor:chai';
import StubCollections from 'meteor/hwillson:stub-collections';
import {sinon} from 'meteor/practicalmeteor:sinon';
// HELPERS
import {withRenderedTemplate, renderTemplate, withDiv} from '../../test-helpers.js';
// COMPONENTS
import '../../../startup/both/schemaDefaults';
import {loadingClassName} from '../../components/loading/loading';
import {Comments} from '../../../api/comments/Comments';
import '../comments.js';
describe("UI/Comments", function() {
beforeEach(function() {
StubCollections.stub(Comments);
Template.registerHelper('_', key => key);
});
afterEach(function() {
Template.deregisterHelper('_');
StubCollections.restore();
Meteor.subscribe.restore();
});
////////////////////////////////////////////////////////
it("renders a loading symbol on load", function (done) {
sinon.stub(Meteor, 'subscribe',() => ({
subscriptionId: Random.id(),
ready:() => false,
}));
withRenderedTemplate(Template.comments, {}, el => {
const target = $(el);
chai.assert.equal(target.find('.' + loadingClassName).length, 1);
done();
});
});
////////////////////////////////////////////////////////
it("displays a message if no comments exist for the given document", function (done) {
sinon.stub(Meteor, 'subscribe',() => ({
subscriptionId: Random.id(),
ready:() => true,
}));
withRenderedTemplate(Template.comments, {docId: Random.id()}, el => {
const target = $(el);
chai.assert.equal(target.find('.' + loadingClassName).length, 0);
chai.assert.equal(target.find('.no-comments').length, 1);
done();
});
});
////////////////////////////////////////////////////////
it("displays comments, if comments are found", function (done) {
sinon.stub(Meteor, 'subscribe',() => ({
subscriptionId: Random.id(),
ready:() => true,
}));
const userId = Random.id();
const commentDoc = {
title: Meteor.user().username,
status: 0,
docId: Random.id(),
description: "this is a comment",
createdAt: new Date().getTime(),
updatedAt: new Date().getTime(),
createdBy: userId,
updatedBy: userId,
};
Comments.insert(commentDoc);
withRenderedTemplate(Template.comments, {docId: Random.id()}, el => {
const target = $(el);
assert.equal(target.find('.' + loadingClassName).length, 0);
assert.equal(target.find('.no-comments').length, 0);
assert.isAbove(target.find('.comment-entry').length, 0);
done();
});
});
////////////////////////////////////////////////////////
it("displays a comment of self different than comments of others", function (done) {
assert.fail("not yet implemented");
})
});