Permalink
Browse files

Rewrite the ‘UniqueItems’ test suite into Mocha

  • Loading branch information...
1 parent af54d82 commit a36e1fc5c12e1609f4c63215ecd0d196054556bd @Baggz committed Mar 7, 2012
Showing with 67 additions and 0 deletions.
  1. +67 −0 tests/json/attributes/uniqueItems.js
@@ -0,0 +1,67 @@
+if (typeof module !== 'undefined' && module.exports) {
+ var expect = require('expect.js');
+ var Amanda = require('../../../dist/latest.js');
+}
+
+/**
+ * UniqueItems
+ * --------------------
+ */
+suite('JSON/Attribute/uniqueItems', function() {
+
+ var count = 0;
+
+ /**
+ * Schema
+ */
+ var schema = {
+ required: true,
+ type: 'array',
+ uniqueItems: true,
+ items: {
+ type: 'string'
+ }
+ };
+
+ /**
+ * Validator
+ */
+ var Validator = new Amanda('json');
+
+ test('should return an error', function() {
+ [
+ ['a', 'a', 'a'],
+ ['a', 'a', 'b'],
+ ['a', 'b', 'a'],
+ ['a', 'b', 'b'],
+ ['a', 'b', 'a', 'b'],
+ [1, 1, 1],
+ [1, 1, 2],
+ [1, 2, 1],
+ [1, 2, 2],
+ [1, 2, 1, 2],
+ ].forEach(function(input) {
+ Validator.validate(input, schema, function(error) {
+ count += 1;
+ expect(error).to.be.ok();
+ });
+ });
+ });
+
+ test('should not return an error', function() {
+ [
+ [],
+ ['a', 'b', 'c'],
+ ].forEach(function(input) {
+ Validator.validate(input, schema, function(error) {
+ count += 1;
+ expect(error).to.not.be.ok();
+ });
+ });
+ });
+
+ test('should run 12 times', function() {
+ expect(count).to.be.eql(12);
+ });
+
+});

0 comments on commit a36e1fc

Please sign in to comment.