【发布时间】: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