Skip to content

Commit

Permalink
fix(routeToComponent): Do not prefix component element with x- unle…
Browse files Browse the repository at this point in the history
…ss necessary.

Closes #3394
  • Loading branch information
christopherthielen committed May 3, 2017
1 parent 1b34e08 commit 60b9ef9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/templateFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ export class TemplateFactory implements TemplateFactoryProvider {
};

let attrs = getComponentBindings(component).map(attributeTpl).join(" ");
let kebobName = "x-" + kebobString(component);
let kebobName = kebobString(component);
if (/^(x|data)-/.exec(kebobName)) {
kebobName = "x-" + kebobName;
}
return `<${kebobName} ${attrs}></${kebobName}>`;
};
}
Expand Down
43 changes: 43 additions & 0 deletions test/templateFactorySpec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as angular from "angular";
import { UIRouter } from '@uirouter/core';

declare let inject;

Expand Down Expand Up @@ -83,4 +84,46 @@ describe('templateFactory', function () {
$httpBackend.flush();
}));
});

if (angular.version.minor >= 5) {
describe('component template builder', () => {
let router: UIRouter, el, rootScope;
let cmp = { template: 'hi' };

beforeEach(() => {
let mod = angular.module('foo', []);
mod.component('myComponent', cmp);
mod.component('dataComponent', cmp);
mod.component('xComponent', cmp);
});
beforeEach(module('foo'));

beforeEach(inject(($uiRouter, $compile, $rootScope) => {
router = $uiRouter;
rootScope = $rootScope;
el = $compile(angular.element('<div><ui-view></ui-view></div>'))($rootScope.$new());
}));

it('should not prefix the components dom element with anything', () => {
router.stateRegistry.register({ name: 'cmp', component: 'myComponent' });
router.stateService.go('cmp');
rootScope.$digest();
expect(el.html()).toMatch(/\<my-component/);
});

it('should prefix the components dom element with x- for components named dataFoo', () => {
router.stateRegistry.register({ name: 'cmp', component: 'dataComponent' });
router.stateService.go('cmp');
rootScope.$digest();
expect(el.html()).toMatch(/\<x-data-component/);
});

it('should prefix the components dom element with x- for components named xFoo', () => {
router.stateRegistry.register({ name: 'cmp', component: 'xComponent' });
router.stateService.go('cmp');
rootScope.$digest();
expect(el.html()).toMatch(/\<x-x-component/);
})
});
}
});

0 comments on commit 60b9ef9

Please sign in to comment.