helper.js
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(function(root, factory){
'use strict';
var define = root.define;
// CommonJS
if (typeof exports === 'object'){
module.exports = factory();
// AMD
} else if (typeof define === 'function' && define.amd){
define(factory);
// Browser
} else {
root.TestHelper = factory();
}
}( ( typeof window === 'object' && window ) || this, function(){
'use strict';
var TestHelper = {},
assert = require('referee').assert;
// helps us make sure that the order of the tests have no impact on their succes
function getUniqueString(){
if ( getUniqueString.uid === undefined ){
getUniqueString.uid = 0;
}
getUniqueString.uid++;
return 'my unique String number ' + getUniqueString.uid.toString();
}
// makes sure that all tokens in the passed array are different
function assertAllTokensDifferent( tokens ){
var length = tokens.length,
j, k;
assert( tokens.length > 0 );
// compare all tokens
for ( j = 0; j < length; j++ ){
for ( k = j + 1; k < length; k++ ){
assert( tokens[j] !== tokens[k] );
}
}
// make sure we actually tested something
assert.equals( j, length );
assert.equals( k, length );
}
TestHelper.getUniqueString = getUniqueString;
TestHelper.assertAllTokensDifferent = assertAllTokensDifferent;
return TestHelper;
}));