mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-23 21:10:01 +00:00
Add an equality assertion that does the right thing for a given property type
This commit is contained in:
parent
0167e60142
commit
18dea2bc6c
@ -19,6 +19,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
assertSimilar: function(type, val1, val2, errorMessage, depth) {
|
||||
depth = depth || 0;
|
||||
if (type == 'float' || type == 'double') {
|
||||
this.assertEqualWithTolerance(val1, val2, errorMessage, depth + 1);
|
||||
}
|
||||
else if (type == 'data') {
|
||||
this.assertArraysEqual(new Uint8Array(val1), val2, errorMessage, depth + 1);
|
||||
}
|
||||
else if (type == 'date') {
|
||||
this.assertEqual(val1.getTime(), val2.getTime(), errorMessage, depth + 1);
|
||||
}
|
||||
else {
|
||||
this.assertEqual(val1, val2, errorMessage, depth + 1);
|
||||
}
|
||||
},
|
||||
|
||||
assertEqual: function(val1, val2, errorMessage, depth) {
|
||||
if (val1 !== val2) {
|
||||
let message = `'${val1}' does not equal expected value '${val2}'`;
|
||||
|
@ -46,22 +46,10 @@ module.exports = {
|
||||
object = realm.create('BasicTypesObject', basicTypesValues);
|
||||
});
|
||||
|
||||
for (var name in schemas.BasicTypes.properties) {
|
||||
var prop = schemas.BasicTypes.properties[name];
|
||||
var type = typeof prop == 'object' ? prop.type : prop;
|
||||
|
||||
if (type == 'float' || type == 'double') {
|
||||
TestCase.assertEqualWithTolerance(object[name], basicTypesValues[name], 0.000001);
|
||||
}
|
||||
else if (type == 'data') {
|
||||
TestCase.assertArraysEqual(new Uint8Array(object[name]), RANDOM_DATA);
|
||||
}
|
||||
else if (type == 'date') {
|
||||
TestCase.assertEqual(object[name].getTime(), basicTypesValues[name].getTime());
|
||||
}
|
||||
else {
|
||||
TestCase.assertEqual(object[name], basicTypesValues[name]);
|
||||
}
|
||||
for (const name in schemas.BasicTypes.properties) {
|
||||
const prop = schemas.BasicTypes.properties[name];
|
||||
const type = typeof prop == 'object' ? prop.type : prop;
|
||||
TestCase.assertSimilar(type, object[name], basicTypesValues[name]);
|
||||
}
|
||||
|
||||
TestCase.assertEqual(object.nonexistent, undefined);
|
||||
|
Loading…
x
Reference in New Issue
Block a user