Search code examples
coffeescriptmocha.jschaikonacha

konacha - helper methods coffeescript


I'm trying to define a helper method in konacha in coffeescript, something like this

@expect_int_is_universal = (i) ->
  expect(i).to.equal 42

describe '#test', ->
  it 'checks if integer is 42', ->
      @expect_int_is_universal(42)

Is it possible in konacha?

edit: error log here:

enter image description here

update: the fix is putting it inside a beforeEach block

beforeEach ->
  @expect_int_is_universal = (i) ->
    expect(i).to.equal 42

describe '#test', ->
  it 'checks if integer is 42', ->
      @expect_int_is_universal(42)

Solution

  • mu is too short hasn't successfully converted his comment as the answer, but i'll provide it here below:

    @ (AKA this) inside your it callback is not the same @ as at the top level so you're defining expect_int_is_universal as a method on one object but trying to call it as a method on another object. Try without the @s. I don't know enough Konocha, Mocha, or Chai to say any more than that