Skip to content

DocumentTitle is undefined when running tests #58

Description

@Birne94

When using this library with TypeScript, I am encountering errors when running tests:

import DocumentTitle from 'react-document-title';

// ...

renderToString(
                    <DocumentTitle title="Hello World">
                        <AppComponen/>
                    </DocumentTitle>
);

My typings file:

// @types/react-document-title.d.ts

declare module 'react-document-title' {
    import * as React from 'react';

    interface DocumentTitleProps {
        title: string;
    }

    export default class DocumentTitle extends React.Component<DocumentTitleProps, any> {
        public static rewind(): string;
        public static peek(): string;
    }
}

This code runs perfectly fine when executed on the server, but during testing it fails:

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Debugging shows that the import of react-document-title simply returns undefined when using jest, but the proper class when running the server.

Does anybody know what might be the cause of this?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions