-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Testing store with jest snapshotting (mobx 5) #1613
Comments
Make sure you are using Jest 23.2 or higher
Op do 28 jun. 2018 16:10 schreef PDarkTemplar <[email protected]>:
… Right now if i want to test my store with snapshot there is a lot of
internal information like this:
...
+ Symbol(mobx did run lazy initializers): true,
+ Symbol(mobx administration): ObservableObjectAdministration$$1 {
+ "defaultEnhancer": [Function],
+ "keysAtom": Atom$$1 {
+ "diffValue": 0,
+ "isBeingObserved": false,
+ "isPendingUnobservation": false,
+ "lastAccessedBy": 0,
+ "lowestObserverState": 2,
+ "name": ***@***.***",
+ "observers": Set {},
+ },
+ "name": ***@***.***",
+ "target": [Circular],
+ "values": Map {
+ "selectedFolder" => SelectedFolder {
+ "id": 1,
+ "name": "test1",
+ "parentFolderId": undefined,
+ "parentOrgUnitId": undefined,
+ "type": undefined,
+ },
+ "breadCrumbs" => Array [],
+ "items" => undefined,
+ "loading" => true,
+ "showSearchList" => false,
+ "openFolderType" => "folder",
...
Which i don't need. So i created small transformation for jest which
automaticly transform observables to JS. But then i lost all information
about class names, and now they are all objects.
So my question is, is there is some tools to deal with this?
If someone interested in my transformation i could create repo for it.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1613>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhEGyT8envon5i5WIwiDxgbr9Bcx4ks5uBOPwgaJpZM4U7dma>
.
|
I update jest to 23.2 and it doesn't help, unfortinatly. |
I created small repro, and find cause, if i create class throught constructor i would see all the internals of mobx. But if i create class in class field, it would be empty. I need middle result :) just plain value with className if it is class. Or it is jest bug, and i should go there? |
You might need to read values first before testing the snapshot (e.g. test
= new Test(); test.test;), otherwise the properties won't live on the
instance yet (due to decorator limitations)
Op vr 29 jun. 2018 om 11:39 schreef PDarkTemplar <[email protected]>:
… I created small repro <https://github.com/PDarkTemplar/MobxTestRepro>,
and find cause if i create class throught constructor i would see all the
internals of mobx. But if i create class in class field, it would be empty.
I need middle result :) just plain value with className if it is class.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1613 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhABZYivBAZA22Ydzy1DDFw8ngnkRks5uBfXagaJpZM4U7dma>
.
|
Ok, so if in first test i read value, i would get exactly the same result as on second test. And i want to cut out |
Will investigate later, as this is exactly what has been fixed here
jestjs/jest#6398,
jestjs/jest#6391, but maybe additional work is
needed to make snapshots follow the same rules now that I think of it :)
Op vr 29 jun. 2018 om 14:19 schreef PDarkTemplar <[email protected]>:
… Ok, so if in first test i read value, i would get exactly the same result
as on second test. And i wont to cut out Symbol(mobx administration) and Symbol(mobx
did run lazy initializers). And i think i could do this only with custom
transformation.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1613 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhAHgeBUkJbhTPG44GwDkIXVIiTOBks5uBhtBgaJpZM4U7dma>
.
|
Any update on this? Is there a workaround? |
You can add a custom snapshot serializer for observables, but you loose the object type (it will print Object { rather than MyType { )
|
A little better
|
@mweststrate any update on this? we are upgrading packages, jest 23.6.0, mobx 5.6.0, and our snapshots grow out of control having all this extra information |
Sorry, no, didn't get around opening an issue or PR on jest (the problem is that it should ignore non-enumerable (symbolic) members. It was fixed a while ago for |
if you have additional input: jestjs/jest#7443 |
Fix has been merged: jestjs/jest#7448, will probably be released anywhere soon. Closing this one in the mean time. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions. |
Right now if i want to test my store with snapshot there is a lot of internal information like this:
Which i don't need. So i created small transformation for jest which automaticly transform observables to JS. But then i lost all information about class names, and now they are all objects.
So my question is, is there is some tools to deal with this?
If someone interested in my transformation i could create repo for it.
The text was updated successfully, but these errors were encountered: