How to test throw new Meteor.Error()

i have a method

Meteor.methods
  itemCreate: (doc) ->
    if !doc.id
      throw new Meteor.Error('invalid-data', "id error")
    else
      insert(doc)

i use meteor-jasmine test

describe('create item', function () {
  it('null id', function () {
    item={}
    expect(Meteor.call('itemCreate', item)).toThrow()
  })
});

doesn’t pass

I think you need to put your code in a function wrapper.
Like this,

describe('create item', function () {
  it('null id', function () {
    item={}
    expect(function () {
       Meteor.call('itemCreate', item);
    }).toThrow()
  })
});
2 Likes