【发布时间】:2018-04-11 12:17:34
【问题描述】:
我的服务器端单元测试有问题。
接下来是我的测试:
import { Meteor } from 'meteor/meteor';
import { Article } from '../../../imports/models/article';
import { Articles } from '../../../imports/collections/articles';
import './articles';
import { Random } from 'meteor/random';
import {Rate} from "../../../imports/models/rate.model";
import { expect, assert } from 'chai';
import {Observable} from "rxjs/Observable";
if (Meteor.isServer) {
describe('Articles', () => {
const userId = Random.id();
beforeEach(() => {
StubCollections.add([Articles]);
StubCollections.stub();
Articles.remove({});
});
it('can delete owned article', async (done) => {
const articleId = await Articles.insert({
title: "string",
content: "string",
owner: userId,
picture_url: "string",
source: "string",
createdAt: new Date()
}).toPromise();
const deleteArticle = Meteor.server.method_handlers["removeArticle"];
// // Run the method with `this` set to the fake invocation
//`enter code here`
const invocation = {userId};
deleteArticle.apply(invocation, [articleId]);
console.log(articleId);
const count = await Articles.find({}).count().toPromise();
// Verify that the method does what we expected
expect(count).equal(0);
StubCollections.restore();
done()
});
});
}
我无法导入存根集合,因为 typescript 没有找到它。
我曾尝试在 tsconfig.json 上安装流星服务器包,但没有成功。
当我删除 StubCollection 时,“Articles.find({})”的超时时间为 2 秒
你有解决办法吗?
【问题讨论】:
标签: unit-testing typescript meteor import server-side