opened
ishan123456789
username_0
<!--
- In Versions, only include the Typegoose version you use (NPM or from GIT)
- in "Code Example" add as many code blocks as needed, but when possible try to use an repo / gist
- in "Do you know *why* it happenes replace the "*no*" if you know why
-->

## Versions

<!--If Possible, please try to use the latest versions-->

<!--"0.0.0" means it is **not** used / unknown-->
- NodeJS: 0.0.0
- Typegoose(NPM): 6.1.8 <!--Please confirm that the verison is 6.0.x or above-->
- mongoose: 5.7.7
- mongodb: 3.3.6
- jest: 24.9.0,

## What is the Problem?

Getting error:
```
TypeError: Invalid schema configuration: `MD` is not a valid type at path `updatedAt`. See http://bit.ly/mongoose-schematypes for a list of valid schema types.

      at Schema.Object.<anonymous>.Schema.interpretAsType (node_modules/mongoose/lib/schema.js:901:11)
      at Schema.Object.<anonymous>.Schema.path (node_modules/mongoose/lib/schema.js:602:27)
      at Schema.add (node_modules/mongoose/lib/schema.js:442:12)
      at Schema.Object.<anonymous>.Schema.setupTimestamp (node_modules/mongoose/lib/schema.js:1094:8)
      at new Schema (node_modules/mongoose/lib/schema.js:138:8)
      at Object._buildSchema (node_modules/@typegoose/typegoose/src/internal/schema.ts:56:11)
      at buildSchema (node_modules/@typegoose/typegoose/src/typegoose.ts:170:9)
      at Object.getModelForClass (node_modules/@typegoose/typegoose/src/typegoose.ts:105:58)
```

## Code Example

```ts

```
## Do you know *when* it happenes?
This error is thrown when I'm trying to run my jest test else it runs fine.

## Do you know *why* it happenes?

*no*
Getting error Invalid schema configuration: `MD` is not a valid type at path `updatedAt`
issue
created
hasezoey
username_1
please give an code example
comment
created
ishan123456789
username_0
@username_1 can you please have a look at https://github.com/username_0/jest-test-failing-example I've pushed some of my code there
comment
created
hasezoey
username_1
you should use `@arrayProp`

---

```ts
logger.warn( // Cannot find name 'logger'.
   "Warning: order && order.deliveryTime not available during scheduleOrderIsLateCheck:",
    order,
);
```

---

otherwise, the only problem i see in your jest tests (and only there) is because you try to mock typegoose
comment
created
ishan123456789
username_0
Thanks a ton dude you're the man! A ton of love and a merry christmas. I would have spent days in figuring out the issue. You're right it's because of mocking interface. Any suggestion on upgrading my concentration on minor things like this?
comment
created
hasezoey
username_1
sorry, i dont know what you mean with that

---

it seems fixed, so i will close this issue
comment
closed
hasezoey
username_1
issue
created
ishan123456789
username_0
Sorry @username_1 I'm still having the same error could this error be due to some package versioning issue? I tried changing it to `arrayProp` but still I'm getting the same error. Can you please have a look again.
comment
created
hasezoey
username_1
@username_0 i know how to use jest, and when i will use it i will use the watchAll script i added (but not pushed) to automaticly re-run if changes happen
comment
created
ishan123456789
username_0
Any suggestion on what the error could be I've fixed to arrayProp and pushed but still getting the same error.
comment
created
hasezoey
username_1
that were just sidenotes from me, when you would have stayed at `prop` you would have got a different schema than you would want, but "nothing actually to do with the error"

and no i couldnt look into it *yet*, but will and report back
comment
created
ishan123456789
username_0
Thanks a lot for your effort
comment
created
hasezoey
username_1
|              ^
      26 |             .mockImplementation(() => Promise.resolve(exampleOrder) as any);
      27 | 
      28 |         await orderService.createOrder(exampleOrder);

      at ModuleMockerClass.spyOn (node_modules/jest-mock/build/index.js:832:13)
      at Object.<anonymous> (src/modules/orders-refactored/tests/orders.service.test.ts:25:14)

```

Note: i personally never used any mocking
comment
created
hasezoey
username_1
Update: when i comment out the call to `advanceTo`, then the `MD at updateAt` vanishes - i dont know what `jest-date-mock` does
comment
created
ishan123456789
username_0
It sets the current time like for `Date.now()` or `moment()` to a specific time.
comment
created
hasezoey
username_1
at `node_modules/jest-date-mock/lib/mockDate.js` `MD is used, it probably comes from there, and mongoose expects an Date not an MD
comment
created
ishan123456789
username_0
Do you know of any alternate to the above library which I can use? To update the current time to some other so that I can write tests with dates defined?
comment
created
hasezoey
username_1
no i dont - why not use normal dates?
comment
created
ishan123456789
username_0
I have Date.now() at some places so to know what it was I have to use the above so that I come to know what it was then match both in the unit test.
comment
created
hasezoey
username_1
when you just want a static date, why not just mock **just** `.now`? (like `Date.now = () => new Date('some time string')`?
comment
created
ishan123456789
username_0
Thanks a lot @username_1 for your time. I used mockdate module as I was using moment so didn't wanted to mock moment.
comment