Meteor测试简单的React使用mocha渲染 - 找不到方法

时间:2016-06-29 03:17:10

标签: meteor reactjs mocha meteor-react

我正在尝试编写一个测试,当数据库中有数据时我的组件如何呈现,我遇到了这个错误:

insert failed: Method '/residents/insert' not found

error

这是我的测试

的客户机/前景/ 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})
  })
}

有没有人知道我为什么会收到这个错误?

0 个答案:

没有答案