gaearon / gaearon/react-document-title

DocumentTitle is undefined when running tests

Open
#58 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.8k
Forks
102
PR merge metrics
No merged PRs in 30d

Description

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

```typescript
import DocumentTitle from 'react-document-title';

// ...

renderToString(



);
```

My typings file:
```typescript
// @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 {
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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.