Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite the ‘UniqueItems’ test suite into Mocha
- 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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); | |||
}); | |||
|
|||
}); |