realm-js: [v3.7.0-alpha.2] CreatedAt must be of type 'date', got 'object'

Goals

Save model on node server with createdAt being new Date()

Expected Results

Model is saved

Actual Results

Got error

Error: LicenseRequestModel.createdAt must be of type 'date', got 'object' (Tue Mar 17 2020 20:03:14 GMT+0100 (Central European Standard Time))

Steps to Reproduce

Try to create new model on node server with new Date()

Code Sample

  static create<T>(this: RealmModelThis<T>, realm: Realm, props: any): T {
    return realm.create<T>(
      this.schema.name,
      {
        ...props,
        createdAt: new Date(),
        modifiedAt: new Date()
      },
      Realm.UpdateMode.All
    );
  }

Version of Realm and Tooling

  • Realm JS SDK Version: v3.7.0-alpha.2
  • Node or React Native: Node v13.3.0
  • Client OS & Version: jest

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 27 (16 by maintainers)

Most upvoted comments

I’m also running into this issue only in jest test (in-memory or not)

the same code directly in node work fine

to get it working in jest:

new Date().toISOString();

Facing this issue myself with jest tests using inMemory Realm.

Works fine on 3.6.5

I forgot to mention that I use in memory realm for Jest tests, maybe there is an issue?

I’m also running into this issue only while using an in-memory Realm for Jest tests.

@kneth The schema I pass to Realm constructor is

  const realmConfig = user.createConfiguration({
    schema,
    schemaVersion,
    sync: {
      url: `~/app`,
      fullSynchronization: true
    }
  });
  const realm = new Realm(realmConfig);

where schema is:

export const schema = [
  ConfigRealmModel.schema,
  CollectionModel.schema,
  CollectionItemModel.schema,
  ImporterAuthenticationModel.schema,
  TransferModel.schema,
  TransferCollectionModel.schema,
  TransferCollectionItemModel.schema,
  LicenseRequestModel.schema
];
export const schemaVersion = 1;

So as I understand, it is done in the same manner by passing JS object directly. Also, it worked with 4.0.0 alpha.

I forgot to mention that I use in memory realm for Jest tests, maybe there is an issue?

@kneth I would like to propose changing label from T-Help to T-Bug