Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

adding more client tests causes $location:nobase error #667

Closed
cdriscol opened this issue Jul 20, 2015 · 2 comments
Closed

adding more client tests causes $location:nobase error #667

cdriscol opened this issue Jul 20, 2015 · 2 comments
Assignees
Milestone

Comments

@cdriscol
Copy link
Contributor

Hey guys -
Anyone know why I'm getting the following error:

$ grunt test:client
...
 [$location:nobase] $location in HTML5 mode requires a <base> tag to be present! 
...

when I add 2 more client tests?

Adding really simple tests (i.e. below) cause this error. Doesn't seem to matter what test file I add extra tests to, it always seems to throw this error when I add 2 more tests. Oddly, if I comment out one of the tests, the error is not thrown.

chat.client.controller.tests.js

    describe('ChatController', function() {
        it('should pass', function() {
            expect(1).toBe(1);
        });

        it('should also pass', function() {
            expect(1).toBe(1);
        });
    });

I can get around the error by not requiring base in $locationProvider.html5Mode

Line 9 in init.js

$locationProvider.html5Mode({enabled:true, requireBase:false}).hashPrefix('!');

But I'm not sure this is a recommended setting for production.

So, anyone have any ideas what's causing this nobase error? Or does anyone know if using requireBase:false is a bad idea for production?

@codydaig
Copy link
Member

I encountered this on another project while writing tests for it, however, I fixed it by adding the following to the HTML page. However, this is already in the main layout html page on the 0.4.0 branch so I'm not sure why that would be failing.

<base href="/">

@cdriscol
Copy link
Contributor Author

Turns out this is caused by karma's default html file that is loaded without any base tag.

node_modules\karma\static\context.html

<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>

looks like Karma has an upcoming fix to allow for custom context.html files so we can add our own custom context.html with a head tag when it's supported.

In the meantime, I decided to add a test file that has a beforeAll which uses angular to add the base tag to the head. I figured this was the least invasive method, but am open to suggestions:

modules\core\tests\client\core.client.tests.js

  beforeAll(function() {
    angular.element(document.querySelector('head')).append('<base href="/">');
  });

@lirantal lirantal added this to the 0.4.0 milestone Jul 20, 2015
@lirantal lirantal self-assigned this Jul 20, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants