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

fix: do not merge arrays (fix #725) #728

Merged
merged 1 commit into from Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions packages/vitest/src/utils/base.ts
Expand Up @@ -87,12 +87,6 @@ export function deepMerge<T extends object = object, S extends object = T>(targe

deepMerge(target[key] as any, source[key] as any)
}
else if (Array.isArray(source[key])) {
if (!target[key])
target[key] = [] as any

(target[key] as any).push(...source[key] as any)
}
else {
target[key] = source[key] as any
}
Expand Down
4 changes: 2 additions & 2 deletions test/core/test/utils.spec.ts
Expand Up @@ -3,7 +3,7 @@ import { deepMerge } from '../../../packages/vitest/src/utils'
import { deepMergeSnapshot } from '../../../packages/vitest/src/integrations/snapshot/port/utils'

describe('deepMerge', () => {
test('non plain objects retain their prototype, arrays are merging, plain objects are merging', () => {
test('non plain objects retain their prototype, arrays are not merging, plain objects are merging', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature looks like a breaking change 🤔

class Test {
baz = 'baz'

Expand Down Expand Up @@ -37,7 +37,7 @@ describe('deepMerge', () => {

expect(merged.test instanceof Test).toBe(true)
expect(merged.num).toBe(40)
expect(merged.array).toEqual([1, 2, 3, 4])
expect(merged.array).toEqual([3, 4])
expect(merged.obj).toEqual({
foo: 'foo',
baz: 'baz',
Expand Down