Permalink
Browse files

Rewrite the ‘maxLength’ test into Mocha

  • Loading branch information...
1 parent 6bdaec8 commit 96b834edd8de22797afe65acdd3dab65f6559e92 @Baggz committed Mar 7, 2012
Showing with 64 additions and 0 deletions.
  1. +64 −0 tests/json/attributes/maxLength.js
@@ -0,0 +1,64 @@
+if (typeof module !== 'undefined' && module.exports) {
+ var expect = require('expect.js');
+ var Amanda = require('../../../dist/latest.js');
+}
+
+/**
+ * MaxLength
+ * --------------------
+ */
+suite('JSON/Attribute/maxLength', function() {
+
+ var count = 0;
+
+ /**
+ * Schema
+ */
+ var schema = {
+ type: 'string',
+ maxLength: 10
+ };
+
+ /**
+ * Validator
+ */
+ var Validator = new Amanda('json');
+
+ test('should return an error', function() {
+ [
+ 'abcdefghijk',
+ 'abcdefghijkl',
+ 'abcdefghijklm'
+ ].forEach(function(input) {
+ Validator.validate(input, schema, function(error) {
+ count += 1;
+ expect(error).to.be.ok();
+ });
+ });
+ });
+
+ test('should not return an error', function() {
+ [
+ 'a',
+ 'ab',
+ 'abc',
+ 'abcd',
+ 'abcde',
+ 'abcdef',
+ 'abcdefg',
+ 'abcdefgh',
+ 'abcdefghi',
+ 'abcdefghij'
+ ].forEach(function(input) {
+ Validator.validate(input, schema, function(error) {
+ count += 1;
+ expect(error).to.not.be.ok();
+ });
+ });
+ });
+
+ test('should run 13 times', function() {
+ expect(count).to.be.eql(13);
+ });
+
+});

0 comments on commit 96b834e

Please sign in to comment.