forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.number.test.js
91 lines (79 loc) · 1.81 KB
/
types.number.test.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Module dependencies.
*/
var mongoose = require('./common').mongoose
, SchemaNumber = mongoose.Schema.Types.Number
, assert = require('assert')
/**
* Test.
*/
describe('types.number', function(){
it('an empty string casts to null', function (done) {
var n = new SchemaNumber();
assert.strictEqual(n.cast(''), null);
done();
})
it('a null number should castForQuery to null', function (done) {
var n = new SchemaNumber();
assert.strictEqual(n.castForQuery(null), null);
done();
})
it('undefined throws number cast error', function (done) {
var n = new SchemaNumber();
var err;
try {
n.cast(undefined);
} catch (e) {
err = e;
}
assert.strictEqual(true, !! err);
done();
})
it('array throws cast number error', function (done) {
var n = new SchemaNumber();
var err;
try {
n.cast([]);
} catch (e) {
err = e;
}
assert.strictEqual(true, !! err);
done();
})
it('three throws cast number error', function (done) {
var n = new SchemaNumber();
var err;
try {
n.cast('three');
} catch (e) {
err = e;
}
assert.strictEqual(true, !! err);
done();
})
it('{} throws cast number error', function (done) {
var n = new SchemaNumber();
var err;
try {
n.cast({});
} catch (e) {
err = e;
}
assert.strictEqual(true, !! err);
done();
})
it('does not throw number cast error', function (done) {
var n = new SchemaNumber();
var items = [1, '2', '0', null, '', new String('47'), new Number(5), Number(47), 09, 0x12];
var err;
try {
for (var i = 0, len = items.length; i < len; ++i) {
n.cast(items[i]);
}
} catch (e) {
err = e;
}
assert.strictEqual(false, !! err, err);
done();
})
})