Object Assertions - dylanparry/ceylon GitHub Wiki

Table of Contents

  1. toBeA
  2. toNotBeA
  3. toInclude
  4. toExclude
  5. toIncludeKey
  6. toExcludeKey
  7. toIncludeKeys
  8. toExcludeKeys

toBeA

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.

Example

class MyClass {
    ...
}

expect(new MyClass()).toBeA(MyClass);

expect(new Error()).toBeA(MyClass); // Assertion Error

Aliases

  • toBeAn

toNotBeA

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.

Example

class MyClass {
    ...
}

expect(new Error()).toNotBeA(MyClass);

expect(new MyClass()).toNotBeA(MyClass); // Assertion Error

Aliases

  • toNotBeAn

toInclude

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.

Example

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

Aliases

  • toContain

toExclude

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.

Example

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

Aliases

  • toNotInclude
  • toNotContain

toIncludeKey

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.

Example

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

Aliases

  • toContainKey

toExcludeKey

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.

Example

const myObject = {
    name: 'My Object',
    description: 'Example',
    subObject: {
        foo: 'bar',
    },
};

expect(myObject).toExcludeKey('foo');
expect(myObject).toExcludeKey('baz');

expect(myObject).toExcludeKey('name'); // Assertion Error

Aliases

  • toNotIncludeKey
  • toNotContainKey

toIncludeKeys

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.

Example

const myObject = {
    name: 'My Object',
    description: 'Example',
    subObject: {
        foo: 'bar',
    },
};

expect(myObject).toIncludeKeys(['name', 'description']);

expect(myObject).toIncludeKeys(['foo', 'baz']); // Assertion Error

Aliases

  • toContainKeys

toExcludeKeys

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.

Example

const myObject = {
    name: 'My Object',
    description: 'Example',
    subObject: {
        foo: 'bar',
    },
};

expect(myObject).toExcludeKeys(['foo', 'baz']);

expect(myObject).toExcludeKeys(['name', 'description']); // Assertion Error

Aliases

  • toNotIncludeKeys
  • toNotContainKeys
⚠️ **GitHub.com Fallback** ⚠️