aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMisko Hevery2010-05-13 16:40:41 -0700
committerMisko Hevery2010-05-13 16:40:41 -0700
commit1bdcf72e456c74256b14f98b26e969b9de637614 (patch)
tree5e99231d79b96f25fc1afd69e4ac4c4fe3ef3cd7 /test
parent22d1464d7abc284dd56d6beaf47e8d85088e01c5 (diff)
downloadangular.js-1bdcf72e456c74256b14f98b26e969b9de637614.tar.bz2
put formatters back.
Diffstat (limited to 'test')
-rw-r--r--test/widgetsSpec.js64
1 files changed, 46 insertions, 18 deletions
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index ecea6223..17120682 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -56,14 +56,6 @@ describe("widget", function(){
expect(scope.$get('list')).toEqual(['1', '2', '3']);
});
- it("should format booleans", function(){
- compile('<input type="checkbox" name="name" value="true" ng-format="boolean"/>', function(){
- scope.name = false;
- });
- expect(scope.name).toEqual(false);
- expect(scope.$element[0].checked).toEqual(false);
- });
-
it("should come up blank if null", function(){
compile('<input type="text" name="age" ng-format="number"/>', function(){
scope.age = null;
@@ -123,6 +115,52 @@ describe("widget", function(){
});
+ describe("checkbox", function(){
+ it("should format booleans", function(){
+ compile('<input type="checkbox" name="name"/>', function(){
+ scope.name = false;
+ });
+ expect(scope.name).toEqual(false);
+ expect(scope.$element[0].checked).toEqual(false);
+ });
+
+ it('should support type="checkbox"', function(){
+ compile('<input type="checkBox" name="checkbox" checked ng-change="action = true"/>');
+ expect(scope.checkbox).toEqual(true);
+ click(element);
+ expect(scope.checkbox).toEqual(false);
+ expect(scope.action).toEqual(true);
+ click(element);
+ expect(scope.checkbox).toEqual(true);
+ });
+
+ it("should use ng-format", function(){
+ angularFormatter('testFormat', {
+ parse: function(value){
+ return value ? "Worked" : "Failed";
+ },
+
+ format: function(value) {
+ if (value == undefined) return value;
+ return value == "Worked";
+ }
+
+ });
+ compile('<input type="checkbox" name="state" ng-format="testFormat" checked/>');
+ expect(scope.state).toEqual("Worked");
+ expect(scope.$element[0].checked).toEqual(true);
+
+ click(scope.$element);
+ expect(scope.state).toEqual("Failed");
+ expect(scope.$element[0].checked).toEqual(false);
+
+ scope.state = "Worked";
+ scope.$eval();
+ expect(scope.state).toEqual("Worked");
+ expect(scope.$element[0].checked).toEqual(true);
+ });
+ });
+
describe("ng-validate", function(){
it("should process ng-validate", function(){
compile('<input type="text" name="price" value="abc" ng-validate="number"/>');
@@ -212,16 +250,6 @@ describe("widget", function(){
expect(scope.$get('clicked')).toEqual(true);
});
- it('should support type="checkbox"', function(){
- compile('<input type="checkBox" name="checkbox" checked ng-change="action = true"/>');
- expect(scope.checkbox).toEqual(true);
- click(element);
- expect(scope.checkbox).toEqual(false);
- expect(scope.action).toEqual(true);
- click(element);
- expect(scope.checkbox).toEqual(true);
- });
-
describe('radio', function(){
it('should support type="radio"', function(){