Hey guys I’m trying to test some of my methods, but I keep getting the following error:
Error: Match error: Expected string, got undefined
at exports.check (packages/check/match.js:34:1)
at Object.deleteComment (server/comments/methods.js:43:3) <= Offending line
at Test.<anonymous> (test/comments.tests.js:38:19)
at run (packages/practicalmeteor:mocha-core/server.js:34:29)
at Context.wrappedFunction (packages/practicalmeteor:mocha-core/server.js:63:33)
And the offending line on the code: comment/methods.js
Meteor.methods({
...omitted code
deleteComment: (authorId, commentId) => {
check(commentId, String); // <= [ERROR]: offending line
check(authorId, String);
const comment = Comments.findOne(commentId);
if (comment.owner !== this.authorId) {
throw new Meteor.Error('not-authorized', alert('You can only delete your own comments'));
}
Comments.remove(commentId);
}
})
tests: comments.test.js
/* eslint-env mocha */
import { Meteor } from 'meteor/meteor'
import { Random } from 'meteor/random'
import { expect } from 'meteor/practicalmeteor:chai'
import { assert } from 'meteor/practicalmeteor:chai'
import '../server/comments/methods.js'
import '../collections/comments.js'
if (Meteor.isServer) {
describe('Comments', () => {
describe('methods', () => {
const userId = Random.id();
const fritkotId = Random.id();
const testDate = new Date();
let commentId;
beforeEach(() => {
Comments.remove(({}));
commentId = Comments.insert({
body: 'Test-content',
author: userId,
fritkotId: fritkotId,
createdAt: testDate
});
});
it('can delete owned comments', () => {
const deleteComment = Meteor.server.method_handlers['deleteComment'];
const invocation = { userId };
deleteComment.apply(invocation, [commentId]);
// assert.equal(Comments.find().count(), 0);
expect( () => { Comments.find().count()} ).to.equal(0)
})
})
}) /* End of Comments */
}