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

[minor] Add failing test for #819 #820

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions __tests__/map-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,40 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
})
expect(mapType1).toBe(mapType2)
})

test("#819 - Set with object maintains order when adding object", () => {
const items = [
{
id: "a"
},
{
id: "b"
}
]

const set = new Set([items[0]])
const newSet = produce(set, draft => {
draft.add(items[1])
})

expect(Array.from(newSet)).toEqual([items[0], items[1]])
})

// More specific varaint of above test covering case of adding non-object item
test("#819 - Set with object maintains order when adding string", () => {
const items = [
{
id: "a"
},
"b"
]

const set = new Set([items[0]])
const newSet = produce(set, draft => {
draft.add(items[1])
})

expect(Array.from(newSet)).toEqual([items[0], items[1]])
})
})
}