Skip to content

Commit

Permalink
Rewrite the ‘UniqueItems’ test suite into Mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
František Hába committed Mar 7, 2012
1 parent af54d82 commit a36e1fc
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions 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.