Permalink
Browse files

Rewrite the ‘maxItems’ test into Mocha

  • Loading branch information...
1 parent 05bd651 commit 6bdaec82b2a3664e6c01ac1ef919e187e89b9390 @Baggz committed Mar 7, 2012
Showing with 57 additions and 0 deletions.
  1. +57 −0 tests/json/attributes/maxItems.js
@@ -0,0 +1,57 @@
+if (typeof module !== 'undefined' && module.exports) {
+ var expect = require('expect.js');
+ var Amanda = require('../../../dist/latest.js');
+}
+
+/**
+ * MaxItems
+ * --------------------
+ */
+suite('JSON/Attribute/maxItems', function() {
+
+ var count = 0;
+
+ /**
+ * Schema
+ */
+ var schema = {
+ type: 'array',
+ maxItems: 2
+ };
+
+ /**
+ * Validator
+ */
+ var Validator = new Amanda('json');
+
+ test('should return an error', function() {
+ [
+ [1, 2, 3],
+ [1, 2, 3, 4],
+ [1, 2, 3, 4, 5]
+ ].forEach(function(input) {
+ Validator.validate(input, schema, function(error) {
+ count += 1;
+ expect(error).to.be.ok();
+ });
+ });
+ });
+
+ test('should not return an error', function() {
+ [
+ [],
+ [1],
+ [1, 2]
+ ].forEach(function(input) {
+ Validator.validate(input, schema, function(error) {
+ count += 1;
+ expect(error).to.not.be.ok();
+ });
+ });
+ });
+
+ test('should run 6 times', function() {
+ expect(count).to.be.eql(6);
+ });
+
+});

0 comments on commit 6bdaec8

Please sign in to comment.