Last Updated: February 25, 2016
· tanema

Testing Angularjs Directives with Testacular/Karma

There were some question on how to test directives if I am doing my templates with slim as I explained in my last "pro tip". I use Karma (formerly Testacular) and have done it as follows. Here is simple example of my linkto directive. (using jasmine)

describe 'link_to', () ->
  subject = null
  elem = null

  beforeEach inject ($rootScope, $compile) ->
    subject = $rootScope.$new()
    elem = angular.element('<div linkto="/locations/abc" search="{dietary_issues: \'peanuts,gluten\'}"></div>')

  it "should call scope.apply", () ->
    spyOn(subject, "$apply")

  it "should call the main helper link_to with correct params", () ->
    spyOn(subject, "link_to")
    expect(subject.link_to).toHaveBeenCalledWith('/locations/abc', { dietary_issues : 'peanuts,gluten' })

1 Response
Add your response

I don't get it, where's the slim?

over 1 year ago ·