Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 36df9b9

Browse files
fix(tests): update mdCompiler to support unwrapped simple text nodes
* Angular compiler (1.5.1 and newer) no longer wraps simple top level text nodes in a span when compiling a template. `.html()` returns the “inner” HTML, which for `<span>hola</span>` is of course, `"hola"` But the inner HTML of `"hola"` is `undefined` [
1 parent 737692f commit 36df9b9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/core/services/compiler/compiler.spec.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,25 @@ describe('$mdCompiler service', function() {
1515
describe('setup', function() {
1616

1717
it('element should use templateUrl', inject(function($templateCache) {
18-
var tpl = 'hola';
18+
var tpl = '<span>hola</span>';
1919
$templateCache.put('template.html', tpl);
2020
var data = compile({
2121
templateUrl: 'template.html'
2222
});
23-
expect(data.element.html()).toBe(tpl);
23+
24+
expect(data.element.html()).toBe('hola');
2425
}));
2526

2627
it('element should use template', function() {
2728
var tpl = 'hello';
2829
var data = compile({
2930
template: tpl
3031
});
31-
expect(data.element.html()).toBe(tpl);
32+
33+
// .html() returns the “inner” HTML
34+
// but inner HTML of "hello" is `undefined`
35+
// so use .text()
36+
expect(data.element.text()).toBe(tpl);
3237
});
3338

3439
it('should support a custom element', function() {
@@ -43,15 +48,15 @@ describe('$mdCompiler service', function() {
4348
var data = compile({
4449
template: tpl
4550
});
46-
expect(data.element.html()).toBe('hello');
51+
expect(data.element.text()).toBe('hello');
4752
});
4853

4954
it('transformTemplate should work with template', function() {
5055
var data = compile({
5156
template: 'world',
5257
transformTemplate: function(tpl) { return 'hello ' + tpl; }
5358
});
54-
expect(data.element.html()).toBe('hello world');
59+
expect(data.element.text()).toBe('hello world');
5560
});
5661

5762
it('transformTemplate receives the options', function() {
@@ -60,7 +65,7 @@ describe('$mdCompiler service', function() {
6065
someArg: 'foo',
6166
transformTemplate: function(tpl, options) { return 'hello ' + tpl + ': ' + options.someArg; }
6267
});
63-
expect(data.element.html()).toBe('hello world: foo');
68+
expect(data.element.text()).toBe('hello world: foo');
6469
});
6570

6671
describe('with resolve and locals options', function() {

0 commit comments

Comments
 (0)