Object Assertions - dylanparry/ceylon GitHub Wiki
expect(item: Object).toBeA(constructor: Function, message?: string): this;Asserts that the object item is an instance of the function constructor.
Outputs an optional message in case of a failed assertion.
class MyClass {
...
}
expect(new MyClass()).toBeA(MyClass);
expect(new Error()).toBeA(MyClass); // Assertion Error- toBeAn
expect(item: Object).toNotBeA(constructor: Function, message?: string): this;Asserts that the object item is not an instance of the function constructor.
Outputs an optional message in case of a failed assertion.
class MyClass {
...
}
expect(new Error()).toNotBeA(MyClass);
expect(new MyClass()).toNotBeA(MyClass); // Assertion Error- toNotBeAn
expect(item: Object).toInclude(value: Object, message?: string): this;Asserts that the object item includes the object value. This checks that item has its own properties that are deeply equal to the properties specified in value.
Outputs an optional message in case of a failed assertion.
const myObject = {
name: 'My Object',
description: 'Example',
subObject: {
name: 'Sub Object',
description: 'Example',
},
};
expect(myObject).toInclude({
name: 'My Object',
});
expect(myObject).toInclude({
name: 'My Object',
description: 'Example',
});
expect(myObject).toInclude({
subObject: {
name: 'Sub Object',
description: 'Example',
}
});
expect(myObject).toInclude({
id: 1,
}); // Assertion Error
expect(myObject).toInclude({
name: 'Sub Object',
}); // Assertion Error- toContain
expect(item: Object).toExclude(value: Object, message?: string): this;Asserts that the object item does not include the object value. This checks that item has none of its own properties that are deeply equal to the properties specified in value.
Outputs an optional message in case of a failed assertion.
const myObject = {
name: 'My Object',
description: 'Example',
subObject: {
name: 'Sub Object',
description: 'Example',
},
};
expect(myObject).toExclude({
foo: 'bar',
});
expect(myObject).toExclude({
name: 'Sub Object',
});
expect(myObject).toExclude({
name: 'My Object',
}); // Assertion Error
expect(myObject).toExclude({
name: 'Foo',
description: 'Example', // <-- this matches a property
}); // Assertion Error- toNotInclude
- toNotContain
expect(item: Object).toIncludeKey(key: string, message?: string): this;Asserts that the object item includes a property key in its own properties.
Outputs an optional message in case of a failed assertion.
const myObject = {
name: 'My Object',
description: 'Example',
subObject: {
foo: 'bar',
},
};
expect(myObject).toIncludeKey('name');
expect(myObject).toIncludeKey('foo'); // Assertion Error
expect(myObject).toIncludeKey('baz'); // Assertion Error- toContainKey
expect(item: Object).toExcludeKey(key: string, message?: string): this;Asserts that the object item does not include a property key in its own properties
Outputs an optional message in case of a failed assertion.
const myObject = {
name: 'My Object',
description: 'Example',
subObject: {
foo: 'bar',
},
};
expect(myObject).toExcludeKey('foo');
expect(myObject).toExcludeKey('baz');
expect(myObject).toExcludeKey('name'); // Assertion Error- toNotIncludeKey
- toNotContainKey
expect(item: Object).toIncludeKeys(key: string[], message?: string): this;Asserts that the object item includes all the properties in keys in its own properties.
Outputs an optional message in case of a failed assertion.
const myObject = {
name: 'My Object',
description: 'Example',
subObject: {
foo: 'bar',
},
};
expect(myObject).toIncludeKeys(['name', 'description']);
expect(myObject).toIncludeKeys(['foo', 'baz']); // Assertion Error- toContainKeys
expect(item: Object).toExcludeKeys(key: string[], message?: string): this;Asserts that the object item does not include any of the properties in keys in its own properties.
Outputs an optional message in case of a failed assertion.
const myObject = {
name: 'My Object',
description: 'Example',
subObject: {
foo: 'bar',
},
};
expect(myObject).toExcludeKeys(['foo', 'baz']);
expect(myObject).toExcludeKeys(['name', 'description']); // Assertion Error- toNotIncludeKeys
- toNotContainKeys