4

In my angular tests I keep getting a Error: Unexpected request: GET 'some/rails/view.html'

I'm using konacha for testing, which uses mocha instead of jasmine. The project is based around a Rails app which is the reason for using konacha.

Here's a really simple sample test that checks if the controller is defined in the Angular app:

describe "ShowAccountCtrl", ->

  beforeEach angular.mock.module('APP_NAME')

  beforeEach inject(($rootScope, $controller) ->
    @scope = $rootScope.$new()
    @ctrl = $controller 'ShowAccountCtrl',
      $scope: @scope
  )


  it "should be defined", ->
    expect(@ctrl).to.not.be.undefined

I've seen some things about $httpBackend.when('GET', /\.html$/).passThrough(); but konacha doesn't seem to have a similar method to passThrough()

These issues always happen upon a $httpBackend.flush().

Has anyone conquered this problem before? Is there a way to ignore requests to rails templates so I can focus on testing functionality of the controllers?

dax
  • 10,779
  • 8
  • 51
  • 86
Luke
  • 2,053
  • 1
  • 18
  • 25

1 Answers1

1

This is because Konacha doesn't support any integration with Rails views. The solution is to load angular's $templateCache manually, similar to what you have to do when using templates with the asset pipeline. To make this work you will need to make your test have the ERB pre-processor (e.g. some_spec.js.coffee.erb).

beforeEach inject ($templateCache) ->    
  template = '/app/templates/view.html'
  content = """
  <%= IO.read(Rails.root.join('/app/templates/view.html')) %>
  """  
  $templateCache.put template, content
Jason Rust
  • 346
  • 4
  • 7