mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
refactor: remove old JSTD assertions
So that we can run the tests even without JSTD :-D
This commit is contained in:
parent
50eb7f15b8
commit
c594f75b4c
5 changed files with 181 additions and 178 deletions
|
|
@ -27,33 +27,33 @@ describe('Binder', function() {
|
|||
it('BindUpdate', inject(function($rootScope, $compile) {
|
||||
$compile('<div ng:init="a=123"/>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
assertEquals(123, $rootScope.a);
|
||||
expect($rootScope.a).toBe(123);
|
||||
}));
|
||||
|
||||
it('ExecuteInitialization', inject(function($rootScope, $compile) {
|
||||
$compile('<div ng:init="a=123">')($rootScope);
|
||||
assertEquals($rootScope.a, 123);
|
||||
expect($rootScope.a).toBe(123);
|
||||
}));
|
||||
|
||||
it('ExecuteInitializationStatements', inject(function($rootScope, $compile) {
|
||||
$compile('<div ng:init="a=123;b=345">')($rootScope);
|
||||
assertEquals($rootScope.a, 123);
|
||||
assertEquals($rootScope.b, 345);
|
||||
expect($rootScope.a).toBe(123);
|
||||
expect($rootScope.b).toBe(345);
|
||||
}));
|
||||
|
||||
it('ApplyTextBindings', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:bind="model.a">x</div>')($rootScope);
|
||||
$rootScope.model = {a:123};
|
||||
$rootScope.$apply();
|
||||
assertEquals('123', element.text());
|
||||
expect(element.text()).toBe('123');
|
||||
}));
|
||||
|
||||
it('ReplaceBindingInTextWithSpan preserve surounding text', function() {
|
||||
assertEquals(this.compileToHtml("<b>a{{b}}c</b>"), '<b>a<span ng:bind="b"></span>c</b>');
|
||||
expect(this.compileToHtml("<b>a{{b}}c</b>")).toBe('<b>a<span ng:bind="b"></span>c</b>');
|
||||
});
|
||||
|
||||
it('ReplaceBindingInTextWithSpan', function() {
|
||||
assertEquals(this.compileToHtml("<b>{{b}}</b>"), '<b><span ng:bind="b"></span></b>');
|
||||
expect(this.compileToHtml("<b>{{b}}</b>")).toBe('<b><span ng:bind="b"></span></b>');
|
||||
});
|
||||
|
||||
it('BindingSpaceConfusesIE', inject(function($rootScope, $compile) {
|
||||
|
|
@ -61,48 +61,47 @@ describe('Binder', function() {
|
|||
var span = document.createElement("span");
|
||||
span.innerHTML = ' ';
|
||||
var nbsp = span.firstChild.nodeValue;
|
||||
assertEquals(
|
||||
'<b><span ng:bind="a"></span><span>'+nbsp+'</span><span ng:bind="b"></span></b>',
|
||||
this.compileToHtml("<b>{{a}} {{b}}</b>"));
|
||||
expect(this.compileToHtml("<b>{{a}} {{b}}</b>")).
|
||||
toBe('<b><span ng:bind="a"></span><span>' + nbsp + '</span><span ng:bind="b"></span></b>');
|
||||
dealoc(($rootScope));
|
||||
assertEquals(
|
||||
'<b><span ng:bind="A"></span><span>'+nbsp+'x </span><span ng:bind="B"></span><span>'+nbsp+'(</span><span ng:bind="C"></span>)</b>',
|
||||
this.compileToHtml("<b>{{A}} x {{B}} ({{C}})</b>"));
|
||||
expect(this.compileToHtml("<b>{{A}} x {{B}} ({{C}})</b>")).
|
||||
toBe('<b><span ng:bind="A"></span><span>' + nbsp + 'x </span><span ng:bind="B"></span>' +
|
||||
'<span>' + nbsp + '(</span><span ng:bind="C"></span>)</b>');
|
||||
}));
|
||||
|
||||
it('BindingOfAttributes', inject(function($rootScope, $compile) {
|
||||
var element = $compile("<a href='http://s/a{{b}}c' foo='x'></a>")($rootScope);
|
||||
var attrbinding = element.attr("ng:bind-attr");
|
||||
var bindings = fromJson(attrbinding);
|
||||
assertEquals("http://s/a{{b}}c", decodeURI(bindings.href));
|
||||
assertTrue(!bindings.foo);
|
||||
expect(decodeURI(bindings.href)).toBe("http://s/a{{b}}c");
|
||||
expect(bindings.foo).toBeFalsy();
|
||||
}));
|
||||
|
||||
it('MarkMultipleAttributes', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<a href="http://s/a{{b}}c" foo="{{d}}"></a>')($rootScope);
|
||||
var attrbinding = element.attr("ng:bind-attr");
|
||||
var bindings = fromJson(attrbinding);
|
||||
assertEquals(bindings.foo, "{{d}}");
|
||||
assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c");
|
||||
expect(bindings.foo).toBe("{{d}}");
|
||||
expect(decodeURI(bindings.href)).toBe("http://s/a{{b}}c");
|
||||
}));
|
||||
|
||||
it('AttributesNoneBound', inject(function($rootScope, $compile) {
|
||||
var a = $compile("<a href='abc' foo='def'></a>")($rootScope);
|
||||
assertEquals(a[0].nodeName, "A");
|
||||
assertTrue(!a.attr("ng:bind-attr"));
|
||||
expect(a[0].nodeName).toBe("A");
|
||||
expect(a.attr("ng:bind-attr")).toBeFalsy();
|
||||
}));
|
||||
|
||||
it('ExistingAttrbindingIsAppended', inject(function($rootScope, $compile) {
|
||||
var a = $compile("<a href='http://s/{{abc}}' ng:bind-attr='{\"b\":\"{{def}}\"}'></a>")($rootScope);
|
||||
assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng:bind-attr'));
|
||||
expect(a.attr('ng:bind-attr')).toBe('{"b":"{{def}}","href":"http://s/{{abc}}"}');
|
||||
}));
|
||||
|
||||
it('AttributesAreEvaluated', inject(function($rootScope, $compile) {
|
||||
var a = $compile('<a ng:bind-attr=\'{"a":"a", "b":"a+b={{a+b}}"}\'></a>')($rootScope);
|
||||
$rootScope.$eval('a=1;b=2');
|
||||
$rootScope.$apply();
|
||||
assertEquals(a.attr('a'), 'a');
|
||||
assertEquals(a.attr('b'), 'a+b=3');
|
||||
expect(a.attr('a')).toBe('a');
|
||||
expect(a.attr('b')).toBe('a+b=3');
|
||||
}));
|
||||
|
||||
it('InputTypeButtonActionExecutesInScope', inject(function($rootScope, $compile) {
|
||||
|
|
@ -114,7 +113,7 @@ describe('Binder', function() {
|
|||
savedCalled = true;
|
||||
};
|
||||
browserTrigger(element, 'click');
|
||||
assertTrue(savedCalled);
|
||||
expect(savedCalled).toBe(true);
|
||||
}));
|
||||
|
||||
it('InputTypeButtonActionExecutesInScope2', inject(function($rootScope, $compile) {
|
||||
|
|
@ -136,7 +135,7 @@ describe('Binder', function() {
|
|||
savedCalled = true;
|
||||
};
|
||||
browserTrigger(element, 'click');
|
||||
assertTrue(savedCalled);
|
||||
expect(savedCalled).toBe(true);
|
||||
}));
|
||||
|
||||
it('RepeaterUpdateBindings', inject(function($rootScope, $compile) {
|
||||
|
|
@ -148,28 +147,31 @@ describe('Binder', function() {
|
|||
$rootScope.model = {items:items};
|
||||
|
||||
$rootScope.$apply();
|
||||
assertEquals('<ul>' +
|
||||
expect(sortedHtml(form)).toBe(
|
||||
'<ul>' +
|
||||
'<#comment></#comment>' +
|
||||
'<li ng:bind="item.a">A</li>' +
|
||||
'<li ng:bind="item.a">B</li>' +
|
||||
'</ul>', sortedHtml(form));
|
||||
'</ul>');
|
||||
|
||||
items.unshift({a:'C'});
|
||||
$rootScope.$apply();
|
||||
assertEquals('<ul>' +
|
||||
expect(sortedHtml(form)).toBe(
|
||||
'<ul>' +
|
||||
'<#comment></#comment>' +
|
||||
'<li ng:bind="item.a">C</li>' +
|
||||
'<li ng:bind="item.a">A</li>' +
|
||||
'<li ng:bind="item.a">B</li>' +
|
||||
'</ul>', sortedHtml(form));
|
||||
'</ul>');
|
||||
|
||||
items.shift();
|
||||
$rootScope.$apply();
|
||||
assertEquals('<ul>' +
|
||||
expect(sortedHtml(form)).toBe(
|
||||
'<ul>' +
|
||||
'<#comment></#comment>' +
|
||||
'<li ng:bind="item.a">A</li>' +
|
||||
'<li ng:bind="item.a">B</li>' +
|
||||
'</ul>', sortedHtml(form));
|
||||
'</ul>');
|
||||
|
||||
items.shift();
|
||||
items.shift();
|
||||
|
|
@ -183,15 +185,16 @@ describe('Binder', function() {
|
|||
'</ul>')($rootScope);
|
||||
$rootScope.model = {items:[{a:"A"}]};
|
||||
$rootScope.$apply();
|
||||
assertEquals('<ul>' +
|
||||
expect(sortedHtml(element)).toBe(
|
||||
'<ul>' +
|
||||
'<#comment></#comment>' +
|
||||
'<li><span ng:bind="item.a">A</span></li>' +
|
||||
'</ul>', sortedHtml(element));
|
||||
'</ul>');
|
||||
}));
|
||||
|
||||
it('DoNotOverwriteCustomAction', function() {
|
||||
var html = this.compileToHtml('<input type="submit" value="Save" action="foo();">');
|
||||
assertTrue(html.indexOf('action="foo();"') > 0 );
|
||||
expect(html.indexOf('action="foo();"')).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('RepeaterAdd', inject(function($rootScope, $compile, $browser) {
|
||||
|
|
@ -242,11 +245,11 @@ describe('Binder', function() {
|
|||
$rootScope.error['throw'] = function() {throw "MyError";};
|
||||
errorLogs.length = 0;
|
||||
$rootScope.$apply();
|
||||
assertEquals(['MyError'], errorLogs.shift());
|
||||
expect(errorLogs.shift()).toBe('MyError');
|
||||
|
||||
$rootScope.error['throw'] = function() {return "ok";};
|
||||
$rootScope.$apply();
|
||||
assertEquals(0, errorLogs.length);
|
||||
expect(errorLogs.length).toBe(0);
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -281,18 +284,20 @@ describe('Binder', function() {
|
|||
$rootScope.model = [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}];
|
||||
$rootScope.$apply();
|
||||
|
||||
assertEquals('<div>'+
|
||||
'<#comment></#comment>'+
|
||||
'<div name="a" ng:bind-attr="{"name":"{{m.name}}"}">'+
|
||||
expect(sortedHtml(element)).toBe(
|
||||
'<div>'+
|
||||
'<#comment></#comment>'+
|
||||
'<ul name="a1" ng:bind-attr="{"name":"{{i}}"}"></ul>'+
|
||||
'<ul name="a2" ng:bind-attr="{"name":"{{i}}"}"></ul>'+
|
||||
'</div>'+
|
||||
'<div name="b" ng:bind-attr="{"name":"{{m.name}}"}">'+
|
||||
'<#comment></#comment>'+
|
||||
'<ul name="b1" ng:bind-attr="{"name":"{{i}}"}"></ul>'+
|
||||
'<ul name="b2" ng:bind-attr="{"name":"{{i}}"}"></ul>'+
|
||||
'</div></div>', sortedHtml(element));
|
||||
'<div name="a" ng:bind-attr="{"name":"{{m.name}}"}">'+
|
||||
'<#comment></#comment>'+
|
||||
'<ul name="a1" ng:bind-attr="{"name":"{{i}}"}"></ul>'+
|
||||
'<ul name="a2" ng:bind-attr="{"name":"{{i}}"}"></ul>'+
|
||||
'</div>'+
|
||||
'<div name="b" ng:bind-attr="{"name":"{{m.name}}"}">'+
|
||||
'<#comment></#comment>'+
|
||||
'<ul name="b1" ng:bind-attr="{"name":"{{i}}"}"></ul>'+
|
||||
'<ul name="b2" ng:bind-attr="{"name":"{{i}}"}"></ul>'+
|
||||
'</div>' +
|
||||
'</div>');
|
||||
}));
|
||||
|
||||
it('HideBindingExpression', inject(function($rootScope, $compile) {
|
||||
|
|
@ -354,12 +359,12 @@ describe('Binder', function() {
|
|||
$rootScope.clazz = 'testClass';
|
||||
$rootScope.$apply();
|
||||
|
||||
assertEquals('<div class="testClass" ng:class="clazz"></div>', sortedHtml(element));
|
||||
expect(sortedHtml(element)).toBe('<div class="testClass" ng:class="clazz"></div>');
|
||||
|
||||
$rootScope.clazz = ['a', 'b'];
|
||||
$rootScope.$apply();
|
||||
|
||||
assertEquals('<div class="a b" ng:class="clazz"></div>', sortedHtml(element));
|
||||
expect(sortedHtml(element)).toBe('<div class="a b" ng:class="clazz"></div>');
|
||||
}));
|
||||
|
||||
it('BindClassEvenOdd', inject(function($rootScope, $compile) {
|
||||
|
|
@ -372,11 +377,10 @@ describe('Binder', function() {
|
|||
var d2 = jqLite(element[0].childNodes[2]);
|
||||
expect(d1.hasClass('o')).toBeTruthy();
|
||||
expect(d2.hasClass('e')).toBeTruthy();
|
||||
assertEquals(
|
||||
expect(sortedHtml(element)).toBe(
|
||||
'<div><#comment></#comment>' +
|
||||
'<div class="o" ng:class-even="\'e\'" ng:class-odd="\'o\'"></div>' +
|
||||
'<div class="e" ng:class-even="\'e\'" ng:class-odd="\'o\'"></div></div>',
|
||||
sortedHtml(element));
|
||||
'<div class="e" ng:class-even="\'e\'" ng:class-odd="\'o\'"></div></div>');
|
||||
}));
|
||||
|
||||
it('BindStyle', inject(function($rootScope, $compile) {
|
||||
|
|
@ -385,7 +389,7 @@ describe('Binder', function() {
|
|||
$rootScope.$eval('style={height: "10px"}');
|
||||
$rootScope.$apply();
|
||||
|
||||
assertEquals("10px", element.css('height'));
|
||||
expect(element.css('height')).toBe("10px");
|
||||
|
||||
$rootScope.$eval('style={}');
|
||||
$rootScope.$apply();
|
||||
|
|
@ -414,7 +418,7 @@ describe('Binder', function() {
|
|||
"</div>")($rootScope);
|
||||
$rootScope.a = 123;
|
||||
$rootScope.$apply();
|
||||
assertEquals('123{{a}}{{b}}{{c}}', element.text());
|
||||
expect(element.text()).toBe('123{{a}}{{b}}{{c}}');
|
||||
}));
|
||||
|
||||
it('ShouldTemplateBindPreElements', inject(function ($rootScope, $compile) {
|
||||
|
|
@ -422,9 +426,8 @@ describe('Binder', function() {
|
|||
$rootScope.name = "World";
|
||||
$rootScope.$apply();
|
||||
|
||||
assertEquals(
|
||||
'<pre ng:bind-template="Hello {{name}}!">Hello World!</pre>',
|
||||
sortedHtml(element));
|
||||
expect( sortedHtml(element)).toBe(
|
||||
'<pre ng:bind-template="Hello {{name}}!">Hello World!</pre>');
|
||||
}));
|
||||
|
||||
it('FillInOptionValueWhenMissing', inject(function($rootScope, $compile) {
|
||||
|
|
@ -463,8 +466,7 @@ describe('Binder', function() {
|
|||
'</div>')($rootScope);
|
||||
$rootScope.$apply();
|
||||
function assertChild(index, disabled) {
|
||||
var child = childNode(element, index);
|
||||
assertEquals(sortedHtml(child), disabled, !!child.attr('disabled'));
|
||||
expect(!!childNode(element, index).attr('disabled')).toBe(disabled);
|
||||
}
|
||||
|
||||
assertChild(0, true);
|
||||
|
|
@ -490,7 +492,7 @@ describe('Binder', function() {
|
|||
var errorLogs = $log.error.logs;
|
||||
|
||||
browserTrigger(first, 'click');
|
||||
assertEquals("ABC", $rootScope.greeting);
|
||||
expect($rootScope.greeting).toBe("ABC");
|
||||
expect(errorLogs).toEqual([]);
|
||||
|
||||
browserTrigger(second, 'click');
|
||||
|
|
@ -509,16 +511,16 @@ describe('Binder', function() {
|
|||
var male = jqLite(element[0].childNodes[1]);
|
||||
|
||||
browserTrigger(female);
|
||||
assertEquals("female", $rootScope.sex);
|
||||
assertEquals(true, female[0].checked);
|
||||
assertEquals(false, male[0].checked);
|
||||
assertEquals("female", female.val());
|
||||
expect($rootScope.sex).toBe("female");
|
||||
expect(female[0].checked).toBe(true);
|
||||
expect(male[0].checked).toBe(false);
|
||||
expect(female.val()).toBe("female");
|
||||
|
||||
browserTrigger(male);
|
||||
assertEquals("male", $rootScope.sex);
|
||||
assertEquals(false, female[0].checked);
|
||||
assertEquals(true, male[0].checked);
|
||||
assertEquals("male", male.val());
|
||||
expect($rootScope.sex).toBe("male");
|
||||
expect(female[0].checked).toBe(false);
|
||||
expect(male[0].checked).toBe(true);
|
||||
expect(male.val()).toBe("male");
|
||||
}));
|
||||
|
||||
it('ItShouldRepeatOnHashes', inject(function($rootScope, $compile) {
|
||||
|
|
@ -527,12 +529,12 @@ describe('Binder', function() {
|
|||
'<li ng:repeat="(k,v) in {a:0,b:1}" ng:bind=\"k + v\"></li>' +
|
||||
'</ul>')($rootScope);
|
||||
$rootScope.$apply();
|
||||
assertEquals('<ul>' +
|
||||
'<#comment></#comment>' +
|
||||
'<li ng:bind=\"k + v\">a0</li>' +
|
||||
'<li ng:bind=\"k + v\">b1</li>' +
|
||||
'</ul>',
|
||||
sortedHtml(element));
|
||||
expect(sortedHtml(element)).toBe(
|
||||
'<ul>' +
|
||||
'<#comment></#comment>' +
|
||||
'<li ng:bind=\"k + v\">a0</li>' +
|
||||
'<li ng:bind=\"k + v\">b1</li>' +
|
||||
'</ul>');
|
||||
}));
|
||||
|
||||
it('ItShouldFireChangeListenersBeforeUpdate', inject(function($rootScope, $compile) {
|
||||
|
|
@ -541,16 +543,14 @@ describe('Binder', function() {
|
|||
$rootScope.$watch("watched", "name=123");
|
||||
$rootScope.watched = "change";
|
||||
$rootScope.$apply();
|
||||
assertEquals(123, $rootScope.name);
|
||||
assertEquals(
|
||||
'<div ng:bind="name">123</div>',
|
||||
sortedHtml(element));
|
||||
expect($rootScope.name).toBe(123);
|
||||
expect(sortedHtml(element)).toBe('<div ng:bind="name">123</div>');
|
||||
}));
|
||||
|
||||
it('ItShouldHandleMultilineBindings', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div>{{\n 1 \n + \n 2 \n}}</div>')($rootScope);
|
||||
$rootScope.$apply();
|
||||
assertEquals("3", element.text());
|
||||
expect(element.text()).toBe("3");
|
||||
}));
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -219,14 +219,14 @@ describe('json', function() {
|
|||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('should read/write to date', function() {
|
||||
var date = new Date("Sep 10 2003 13:02:03 GMT");
|
||||
assertEquals("2003-09-10T13:02:03.000Z", jsonDateToString(date));
|
||||
assertEquals(date.getTime(), jsonStringToDate(jsonDateToString(date)).getTime());
|
||||
expect(jsonDateToString(date)).toBe("2003-09-10T13:02:03.000Z");
|
||||
expect(jsonStringToDate(jsonDateToString(date)).getTime()).toBe(date.getTime());
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
it('should convert to date', function() {
|
||||
//full ISO8061
|
||||
expect(jsonStringToDate("2003-09-10T13:02:03.000Z")).
|
||||
|
|
@ -249,31 +249,31 @@ describe('json', function() {
|
|||
toEqual(new Date("Sep 10 2003 00:00:00 GMT"));
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('should parse date', function() {
|
||||
var date = jsonStringToDate("2003-09-10T13:02:03.000Z");
|
||||
assertEquals("2003-09-10T13:02:03.000Z", jsonDateToString(date));
|
||||
assertEquals("str", jsonStringToDate("str"));
|
||||
expect(jsonDateToString(date)).toBe("2003-09-10T13:02:03.000Z");
|
||||
expect(jsonStringToDate("str")).toBe("str");
|
||||
});
|
||||
|
||||
|
||||
describe('string', function() {
|
||||
it('should quote', function() {
|
||||
assertEquals(quoteUnicode('a'), '"a"');
|
||||
assertEquals(quoteUnicode('\\'), '"\\\\"');
|
||||
assertEquals(quoteUnicode("'a'"), '"\'a\'"');
|
||||
assertEquals(quoteUnicode('"a"'), '"\\"a\\""');
|
||||
assertEquals(quoteUnicode('\n\f\r\t'), '"\\n\\f\\r\\t"');
|
||||
expect(quoteUnicode('a')).toBe('"a"');
|
||||
expect(quoteUnicode('\\')).toBe('"\\\\"');
|
||||
expect(quoteUnicode("'a'")).toBe('"\'a\'"');
|
||||
expect(quoteUnicode('"a"')).toBe('"\\"a\\""');
|
||||
expect(quoteUnicode('\n\f\r\t')).toBe('"\\n\\f\\r\\t"');
|
||||
});
|
||||
|
||||
it('should quote slashes', function() {
|
||||
assertEquals('"7\\\\\\\"7"', quoteUnicode("7\\\"7"));
|
||||
expect(quoteUnicode("7\\\"7")).toBe('"7\\\\\\\"7"');
|
||||
});
|
||||
|
||||
it('should quote unicode', function() {
|
||||
assertEquals('"abc\\u00a0def"', quoteUnicode('abc\u00A0def'));
|
||||
expect(quoteUnicode('abc\u00A0def')).toBe('"abc\\u00a0def"');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -173,87 +173,87 @@ describe("markups", function() {
|
|||
|
||||
it('should Parse Text With No Bindings', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("a");
|
||||
assertEquals(parts.length, 1);
|
||||
assertEquals(parts[0], "a");
|
||||
assertTrue(!binding(parts[0]));
|
||||
expect(parts.length).toBe(1);
|
||||
expect(parts[0]).toBe("a");
|
||||
expect(binding(parts[0])).toBeFalsy();
|
||||
}));
|
||||
|
||||
it('should Parse Empty Text', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("");
|
||||
assertEquals(parts.length, 1);
|
||||
assertEquals(parts[0], "");
|
||||
assertTrue(!binding(parts[0]));
|
||||
expect(parts.length).toBe(1);
|
||||
expect(parts[0]).toBe("");
|
||||
expect(binding(parts[0])).toBeFalsy();
|
||||
}));
|
||||
|
||||
it('should Parse Inner Binding', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("a{{b}}C");
|
||||
assertEquals(parts.length, 3);
|
||||
assertEquals(parts[0], "a");
|
||||
assertTrue(!binding(parts[0]));
|
||||
assertEquals(parts[1], "{{b}}");
|
||||
assertEquals(binding(parts[1]), "b");
|
||||
assertEquals(parts[2], "C");
|
||||
assertTrue(!binding(parts[2]));
|
||||
expect(parts.length).toBe(3);
|
||||
expect(parts[0]).toBe("a");
|
||||
expect(binding(parts[0])).toBeFalsy();
|
||||
expect(parts[1]).toBe("{{b}}");
|
||||
expect(binding(parts[1])).toBe("b");
|
||||
expect(parts[2]).toBe("C");
|
||||
expect(binding(parts[2])).toBeFalsy();
|
||||
}));
|
||||
|
||||
it('should Parse Ending Binding', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("a{{b}}");
|
||||
assertEquals(parts.length, 2);
|
||||
assertEquals(parts[0], "a");
|
||||
assertTrue(!binding(parts[0]));
|
||||
assertEquals(parts[1], "{{b}}");
|
||||
assertEquals(binding(parts[1]), "b");
|
||||
expect(parts.length).toBe(2);
|
||||
expect(parts[0]).toBe("a");
|
||||
expect(binding(parts[0])).toBeFalsy();
|
||||
expect(parts[1]).toBe("{{b}}");
|
||||
expect(binding(parts[1])).toBe("b");
|
||||
}));
|
||||
|
||||
it('should Parse Begging Binding', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("{{b}}c");
|
||||
assertEquals(parts.length, 2);
|
||||
assertEquals(parts[0], "{{b}}");
|
||||
assertEquals(binding(parts[0]), "b");
|
||||
assertEquals(parts[1], "c");
|
||||
assertTrue(!binding(parts[1]));
|
||||
expect(parts.length).toBe(2);
|
||||
expect(parts[0]).toBe("{{b}}");
|
||||
expect(binding(parts[0])).toBe("b");
|
||||
expect(parts[1]).toBe("c");
|
||||
expect(binding(parts[1])).toBeFalsy();
|
||||
}));
|
||||
|
||||
it('should Parse Loan Binding', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("{{b}}");
|
||||
assertEquals(parts.length, 1);
|
||||
assertEquals(parts[0], "{{b}}");
|
||||
assertEquals(binding(parts[0]), "b");
|
||||
expect(parts.length).toBe(1);
|
||||
expect(parts[0]).toBe("{{b}}");
|
||||
expect(binding(parts[0])).toBe("b");
|
||||
}));
|
||||
|
||||
it('should Parse Two Bindings', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("{{b}}{{c}}");
|
||||
assertEquals(parts.length, 2);
|
||||
assertEquals(parts[0], "{{b}}");
|
||||
assertEquals(binding(parts[0]), "b");
|
||||
assertEquals(parts[1], "{{c}}");
|
||||
assertEquals(binding(parts[1]), "c");
|
||||
expect(parts.length).toBe(2);
|
||||
expect(parts[0]).toBe("{{b}}");
|
||||
expect(binding(parts[0])).toBe("b");
|
||||
expect(parts[1]).toBe("{{c}}");
|
||||
expect(binding(parts[1])).toBe("c");
|
||||
}));
|
||||
|
||||
it('should Parse Two Bindings With Text In Middle', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("{{b}}x{{c}}");
|
||||
assertEquals(parts.length, 3);
|
||||
assertEquals(parts[0], "{{b}}");
|
||||
assertEquals(binding(parts[0]), "b");
|
||||
assertEquals(parts[1], "x");
|
||||
assertTrue(!binding(parts[1]));
|
||||
assertEquals(parts[2], "{{c}}");
|
||||
assertEquals(binding(parts[2]), "c");
|
||||
expect(parts.length).toBe(3);
|
||||
expect(parts[0]).toBe("{{b}}");
|
||||
expect(binding(parts[0])).toBe("b");
|
||||
expect(parts[1]).toBe("x");
|
||||
expect(binding(parts[1])).toBeFalsy();
|
||||
expect(parts[2]).toBe("{{c}}");
|
||||
expect(binding(parts[2])).toBe("c");
|
||||
}));
|
||||
|
||||
it('should Parse Multiline', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings('"X\nY{{A\nB}}C\nD"');
|
||||
assertTrue(!!binding('{{A\nB}}'));
|
||||
assertEquals(parts.length, 3);
|
||||
assertEquals(parts[0], '"X\nY');
|
||||
assertEquals(parts[1], '{{A\nB}}');
|
||||
assertEquals(parts[2], 'C\nD"');
|
||||
expect(binding('{{A\nB}}')).toBeTruthy();
|
||||
expect(parts.length).toBe(3);
|
||||
expect(parts[0]).toBe('"X\nY');
|
||||
expect(parts[1]).toBe('{{A\nB}}');
|
||||
expect(parts[2]).toBe('C\nD"');
|
||||
}));
|
||||
|
||||
it('should Has Binding', inject(function($rootScope, $compile) {
|
||||
assertTrue(hasBindings(parseBindings("{{a}}")));
|
||||
assertTrue(!hasBindings(parseBindings("a")));
|
||||
assertTrue(hasBindings(parseBindings("{{b}}x{{c}}")));
|
||||
expect(hasBindings(parseBindings("{{a}}"))).toBe(true);
|
||||
expect(hasBindings(parseBindings("a"))).toBeFalsy();
|
||||
expect(hasBindings(parseBindings("{{b}}x{{c}}"))).toBe(true);
|
||||
}));
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,67 +2,68 @@
|
|||
|
||||
describe('Filter: filter', function() {
|
||||
var filter;
|
||||
|
||||
|
||||
beforeEach(inject(function($filter){
|
||||
filter = $filter('filter');
|
||||
}));
|
||||
|
||||
|
||||
it('should filter by string', function() {
|
||||
var items = ["MIsKO", {name:"shyam"}, ["adam"], 1234];
|
||||
assertEquals(4, filter(items, "").length);
|
||||
assertEquals(4, filter(items, undefined).length);
|
||||
var items = ['MIsKO', {name: 'shyam'}, ['adam'], 1234];
|
||||
expect(filter(items, '').length).toBe(4);
|
||||
expect(filter(items, undefined).length).toBe(4);
|
||||
|
||||
assertEquals(1, filter(items, 'iSk').length);
|
||||
assertEquals("MIsKO", filter(items, 'isk')[0]);
|
||||
expect(filter(items, 'iSk').length).toBe(1);
|
||||
expect(filter(items, 'isk')[0]).toBe('MIsKO');
|
||||
|
||||
assertEquals(1, filter(items, 'yam').length);
|
||||
assertEquals(items[1], filter(items, 'yam')[0]);
|
||||
expect(filter(items, 'yam').length).toBe(1);
|
||||
expect(filter(items, 'yam')[0]).toEqual(items[1]);
|
||||
|
||||
assertEquals(1, filter(items, 'da').length);
|
||||
assertEquals(items[2], filter(items, 'da')[0]);
|
||||
expect(filter(items, 'da').length).toBe(1);
|
||||
expect(filter(items, 'da')[0]).toEqual(items[2]);
|
||||
|
||||
assertEquals(1, filter(items, '34').length);
|
||||
assertEquals(1234, filter(items, '34')[0]);
|
||||
expect(filter(items, '34').length).toBe(1);
|
||||
expect(filter(items, '34')[0]).toBe(1234);
|
||||
|
||||
assertEquals(0, filter(items, "I don't exist").length);
|
||||
expect(filter(items, "I don't exist").length).toBe(0);
|
||||
});
|
||||
|
||||
it('should not read $ properties', function() {
|
||||
assertEquals("", "".charAt(0)); // assumption
|
||||
var items = [{$name:"misko"}];
|
||||
assertEquals(0, filter(items, "misko").length);
|
||||
expect(''.charAt(0)).toBe(''); // assumption
|
||||
|
||||
var items = [{$name: 'misko'}];
|
||||
expect(filter(items, 'misko').length).toBe(0);
|
||||
});
|
||||
|
||||
it('should filter on specific property', function() {
|
||||
var items = [{ignore:"a", name:"a"}, {ignore:"a", name:"abc"}];
|
||||
assertEquals(2, filter(items, {}).length);
|
||||
var items = [{ignore: 'a', name: 'a'}, {ignore: 'a', name: 'abc'}];
|
||||
expect(filter(items, {}).length).toBe(2);
|
||||
|
||||
assertEquals(2, filter(items, {name:'a'}).length);
|
||||
expect(filter(items, {name: 'a'}).length).toBe(2);
|
||||
|
||||
assertEquals(1, filter(items, {name:'b'}).length);
|
||||
assertEquals("abc", filter(items, {name:'b'})[0].name);
|
||||
expect(filter(items, {name: 'b'}).length).toBe(1);
|
||||
expect(filter(items, {name: 'b'})[0].name).toBe('abc');
|
||||
});
|
||||
|
||||
it('should take function as predicate', function() {
|
||||
var items = [{name:"a"}, {name:"abc", done:true}];
|
||||
assertEquals(1, filter(items, function(i) {return i.done;}).length);
|
||||
var items = [{name: 'a'}, {name: 'abc', done: true}];
|
||||
expect(filter(items, function(i) {return i.done;}).length).toBe(1);
|
||||
});
|
||||
|
||||
it('should take object as perdicate', function() {
|
||||
var items = [{first:"misko", last:"hevery"},
|
||||
{first:"adam", last:"abrons"}];
|
||||
var items = [{first: 'misko', last: 'hevery'},
|
||||
{first: 'adam', last: 'abrons'}];
|
||||
|
||||
assertEquals(2, filter(items, {first:'', last:''}).length);
|
||||
assertEquals(1, filter(items, {first:'', last:'hevery'}).length);
|
||||
assertEquals(0, filter(items, {first:'adam', last:'hevery'}).length);
|
||||
assertEquals(1, filter(items, {first:'misko', last:'hevery'}).length);
|
||||
assertEquals(items[0], filter(items, {first:'misko', last:'hevery'})[0]);
|
||||
expect(filter(items, {first:'', last:''}).length).toBe(2);
|
||||
expect(filter(items, {first:'', last:'hevery'}).length).toBe(1);
|
||||
expect(filter(items, {first:'adam', last:'hevery'}).length).toBe(0);
|
||||
expect(filter(items, {first:'misko', last:'hevery'}).length).toBe(1);
|
||||
expect(filter(items, {first:'misko', last:'hevery'})[0]).toEqual(items[0]);
|
||||
});
|
||||
|
||||
it('should support negation operator', function() {
|
||||
var items = ["misko", "adam"];
|
||||
var items = ['misko', 'adam'];
|
||||
|
||||
assertEquals(1, filter(items, '!isk').length);
|
||||
assertEquals(items[1], filter(items, '!isk')[0]);
|
||||
expect(filter(items, '!isk').length).toBe(1);
|
||||
expect(filter(items, '!isk')[0]).toEqual(items[1]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -174,12 +174,14 @@ function isCssVisible(node) {
|
|||
}
|
||||
|
||||
function assertHidden(node) {
|
||||
assertFalse("Node should be hidden but vas visible: " +
|
||||
angular.module.ngMock.dump(node), isCssVisible(node));
|
||||
if (isCssVisible(node)) {
|
||||
throw new Error('Node should be hidden but was visible: ' + angular.module.ngMock.dump(node));
|
||||
}
|
||||
}
|
||||
|
||||
function assertVisible(node) {
|
||||
assertTrue("Node should be visible but vas hidden: " +
|
||||
angular.module.ngMock.dump(node), isCssVisible(node));
|
||||
if (!isCssVisible(node)) {
|
||||
throw new Error('Node should be visible but was hidden: ' + angular.module.ngMock.dump(node));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue