【问题标题】:Meteor / Jasmine Object is not defined流星/茉莉花对象未定义
【发布时间】:2015-04-24 15:48:26
【问题描述】:

我正在尝试了解如何使用 jasmine 编写 server-unit-test

这是我目前所拥有的:

/both/posts.coffee

@Posts = new Mongo.Collection('posts');

class @Post extends Minimongoid
  @_collection: @Posts

  @defaults:
    title: ''

  validate: ->
    unless @title.length > 5
      @error('title', 'Title is required and should be longer than 5 letters.')

/tests/server/unit/posts/spec/postSpec.coffee

describe 'Post', ->
  post = undefined
  beforeEach ->
    post = new Post()

  describe 'fields', ->
    it 'should be able to assign title with strings', ->
      title = "The Title"
      post.title = title

      expect(post.title).toBe title

服务器控制台:

(STDERR) [sanjo:jasmine]: The code has syntax errors. [ReferenceError: Minimongoid is not defined]

那里有什么问题?我怎样才能通过这个简单的测试?

【问题讨论】:

  • 我认为从 jasmine 生成的 'Post' 的存根/模拟存在问题。尝试为此集合编写自己的存根。
  • 那是有线的。我想做的是一个测试,它通过使用 Collection2(模式)和 Minimongoid 来确认集合具有某些字段和验证。所以你的意思是我必须创建一个额外的文件来“模拟”测试文件夹中的集合“帖子”来测试这个?
  • 在服务器单元测试模式下从此处读取github.com/Sanjo/meteor-jasmine 。你想做的更像是一个集成测试。

标签: meteor coffeescript jasmine


【解决方案1】:

当我将 UNIT-Test 的全部内容移动到 INTEGRATION-Test 文件夹并在代码前添加

/tests/server/integration/posts/spec/postSpec.coffee

Jasmine.onTest ->
 # my code

现在全是绿色的。谢谢@Marius Darila

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-15
    • 1970-01-01
    • 2016-10-13
    • 2018-06-26
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多