Angular testing, using mocha, unexpected requests

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

I use konacha for testing, which uses mocha instead of jasmine. The project is based on the Rails application, which is the reason for using konacha.

Here is a really simple test example that checks if a controller is defined in an angular application:

 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 saw something about $httpBackend.when('GET', /\.html$/).passThrough(); but konacha doesn't seem to have a similar method for passThrough()

These problems always occur with $httpBackend.flush() .

Has anyone beat this issue before? Is there a way to ignore rails template requests so that I can focus on testing the functionality of the controllers?

+4
source share
1 answer

This is because Konacha does not support any integration with Rails views . The solution is to download angular $templateCache manually, similar to what you need to do when using templates with an asset pipeline . To do this, you will need to make your test a preliminary ERB 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 
+1
source

Source: https://habr.com/ru/post/1483815/


All Articles