Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'toUTCString' of undefined #716

Closed
ummahusla opened this issue Dec 5, 2016 · 4 comments
Closed

Cannot read property 'toUTCString' of undefined #716

ummahusla opened this issue Dec 5, 2016 · 4 comments

Comments

@ummahusla
Copy link

ummahusla commented Dec 5, 2016

I testing out one of the react components and came across a weird issue. When I try to shallow the component, I get "before each" hook: Cannot read property 'toUTCString' of undefined. It's clearly something I not expect.

I've done a small researched and I found that a lot of people were struggling with toString() method as well and seems to be fixed, but issue toUTCString() with still exists.

Issues: #519, #453, etc..

Update: I've tried to replace toUTCString with toString still got the same issue TypeError: Cannot read property 'toString' of undefined.


Component

const ConversationMessage = ({author, text, date, isOutGoing}: ConversationMessageProps) => (
  <div className="row">
    <div className={"col-md-8 " + (isOutGoing ? "col-md-offset-4 out-going" : "not-out-going")}>
      <div className="message-body-wrap">
       ...
      </div>
      <div className="message-meta-data">
        <p>
          {author} - {date.toUTCString()}
        </p>
      </div>
    </div>
  </div>
);

Test

const message = [{
  "author": "Geoff Winters",
  "text": "test",
  "date": "2016-11-15T12:08:00",
  "isOutGoing": true
}];

var wrapper;

beforeEach(() => {
  wrapper = shallow(
    <ConversationMessage
      author={message.author}
      text={message.text}
      date={message.date}
      isOutGoing={message.isOutGoing}
    />
  );
});

describe('Conversation Message Component', () => {
  it('should have correct values ', () => {
    console.log(wrapper.debug());
    expect(wrapper.find('div').first().hasClass("row"));
  });
});
@ummahusla ummahusla changed the title Cannot read property 'toUTCString' of undefined Cannot read property 'toUTCString' of undefined when I swallow the component Dec 5, 2016
@ummahusla ummahusla changed the title Cannot read property 'toUTCString' of undefined when I swallow the component Cannot read property 'toUTCString' of undefined Dec 5, 2016
@ummahusla
Copy link
Author

ummahusla commented Dec 5, 2016 via email

@ljharb
Copy link
Member

ljharb commented Dec 5, 2016

You were passing a string as a date, and the prop expected a date object.

@aweary
Copy link
Collaborator

aweary commented Dec 5, 2016

Sorry, I deleted my comment that @ummahusla was responding to.

toString would have been defined on a string, and he stated that it threw the same error with that. The issue was (partially) that message is an array and it he was passing in message.date instead of message[0].date

@ummahusla
Copy link
Author

ummahusla commented Dec 5, 2016

@aweary Nah it's okay, it was my bad there. Didn't spot it at first and later on forgot to close the issue here.

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

No branches or pull requests

3 participants