Make toEqual matcher report the difference between objects

- Mismatches deep within object/array structures are pinpointed with a JsonPath-like syntax.
This commit is contained in:
Ben Christel
2016-07-18 15:17:00 -07:00
committed by Ben Christel
parent 5a76e59d5b
commit d5e6bf47ed
17 changed files with 2251 additions and 1156 deletions

View File

@@ -0,0 +1,43 @@
describe('ObjectPath', function() {
var ObjectPath = jasmineUnderTest.ObjectPath;
it('represents the path to a node in an object tree', function() {
expect(new ObjectPath(['foo', 'bar']).toString()).toEqual('$.foo.bar');
});
it('has a depth', function() {
expect(new ObjectPath().depth()).toEqual(0);
expect(new ObjectPath(['foo']).depth()).toEqual(1);
});
it('renders numbers as array access', function() {
expect(new ObjectPath(['foo', 0]).toString()).toEqual('$.foo[0]');
});
it('renders properties that are valid identifiers with dot notation', function() {
expect(new ObjectPath(['foo123']).toString()).toEqual('$.foo123');
expect(new ObjectPath(['x_y']).toString()).toEqual('$.x_y');
expect(new ObjectPath(['A$B']).toString()).toEqual('$.A$B');
});
it('renders properties with non-identifier-safe characters with square bracket notation', function() {
expect(new ObjectPath(['a b c']).toString()).toEqual("$['a b c']");
expect(new ObjectPath(['1hello']).toString()).toEqual("$['1hello']");
});
it('renders as the empty string when empty', function() {
expect(new ObjectPath().toString()).toEqual('');
});
it('stringifies properties that are not strings or numbers', function() {
expect(new ObjectPath([{}]).toString()).toEqual("$['[object Object]']");
});
it('can be created based on another path', function() {
var root = new ObjectPath();
var path = root.add('foo');
expect(path.toString()).toEqual('$.foo');
expect(root.toString()).toEqual('');
})
});