我正在尝试编写一个测试来测试当数据库中有数据时我的组件如何呈现,我遇到了这个错误:
insert failed: Method '/residents/insert' not found
这是我的测试
客户/前景/Prospect.tests.js
import { Meteor } from 'meteor/meteor';
import React from 'react';
import { mount, shallow } from 'enzyme';
import Prospects from './Prospects'
import { chai } from 'meteor/practicalmeteor:chai'
import { resetDatabase } from 'meteor/xolvio:cleaner';
import { Factory } from 'meteor/dburles:factory'
import { Residents } from './../../collections/residents.jsx';
import StubCollections from 'meteor/hwillson:stub-collections';
import { Random } from 'meteor/random';
describe('Prospects', () => {
if (Meteor.isServer) return;
it('renders with no prospects', () => {
const item = mount(<Prospects />);
chai.assert(item.find('p').hasClass('no-prospects'))
});
it('renders with prospects', () => {
StubCollections.stub(Residents);
Residents.insert({
cId: Random.id(),
name: {first: "John", last: "Smith"},
status: 'prospect',
chai.assert(item.find('p').hasClass('prospects'))
})
});
});
这是我的收藏
收藏品/residents.jsx
import { Mongo } from 'meteor/mongo'
import { Factory } from 'meteor/dburles:factory'
import faker from 'meteor/practicalmeteor:faker';
import { Random } from 'meteor/random';
export const Residents = new Mongo.Collection('residents')
const productTypeSchema = new SimpleSchema({
list: {type: [String], optional: true},
other: {type: String, optional: true}
})
const residentSchema = new SimpleSchema({
cId: { type: String },
name: { type: nameSchema },
status: { type: String }
})
Residents.attachSchema(residentSchema)
// METHODS
Meteor.methods({
'residents.insert'(resident) {
Residents.insert(resident)
}
})
// PUBLICATIONS
if(Meteor.isServer) {
Meteor.publish('residents', function() {
return Residents.find()
})
Meteor.publish('resident', function(id) {
return Residents.find({_id: id})
})
}
有谁知道我为什么会收到这个错误?