Skip to content
Browse files

Adds assertType assertion

  • Loading branch information...
1 parent 3cd3ff3 commit c386a138786fac569d901312ede3d84d64f7ffc2 @elcuervo committed May 10, 2012
Showing with 19 additions and 14 deletions.
  1. +8 −0 lib/gerbil.js
  2. +10 −14 test/gerbil.js
  3. +1 −0 test/test.js
View
8 lib/gerbil.js
@@ -266,6 +266,14 @@ Gerbil.Test.prototype = {
if (errorMessage) throw Gerbil.Error({message: errorMessage});
},
+ assertType: function(type, object) {
+ this.assertions++;
+ if(object.constructor != type) {
+ var message = 'Expected to be ' + type.name + ' but ' + object.constructor.name + ' was found.';
+ throw Gerbil.Error({ message: message });
+ }
+ },
+
assertEqual: function(first, second) {
if(first == undefined || second == undefined) {
throw Gerbil.Error({
View
24 test/gerbil.js
@@ -21,6 +21,16 @@ scenario("Gerbil - Assertions", {
})
});
},
+
+ "should be able to validate the type of an object": function(g) {
+ g.assertType(Function, function() {});
+ g.assertType(Number, 42);
+ g.assertType(String, 'Gerbil');
+
+ g.assertThrow(Error, function() {
+ g.assertType(Function, 42);
+ });
+ }
});
scenario("Gerbil - setTimeout", {
@@ -103,17 +113,3 @@ scenario('Gerbil - asyncronous code', {
}
});
-
-scenario('Gerbil - config object + callback', {
- 'config': function(c) {
- c.start = function(o) {
- };
-
- c.finish = function(results) {
- };
- },
-
- 'test': function(g) {
- g.assert(true);
- }
-});
View
1 test/test.js
@@ -28,6 +28,7 @@ scenario("Validate some stuff", {
"take a long time": function(g) {
for(var i = 0; i < 10000000; i++) {}
g.assertEqual(i, 10000000);
+ g.assertType(Function, 23);
},
"show error on async code": function(g) {

0 comments on commit c386a13

Please sign in to comment.
Something went wrong with that request. Please try again.