Skip to content

Commit

Permalink
feat: Add test for RefStateEditor.set
Browse files Browse the repository at this point in the history
  • Loading branch information
Azurewarth0920 committed Feb 3, 2024
1 parent 814fec6 commit c6a7404
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RefStateEditor } from '../editor'

describe('editor: RefStateEditor', () => {
const editor = new RefStateEditor()

// eslint-disable-next-line test/consistent-test-it
test.each([
// Add new key.
{ refValue: { foo: 'bar' }, newValue: { foo: 'bar', bar: 'baz' } },
// Add new key and modify origin value.
{ refValue: { foo: 'bar' }, newValue: { foo: 'barr', bar: 'baz' } },
// Modify origin value.
{ refValue: { foo: 'bar' }, newValue: { foo: 'barr' } },
// Remove key.
{ refValue: { foo: 'bar' }, newValue: {} },
// Remove key and modify origin value.
{ refValue: { foo: 'bar' }, newValue: { foo: 'barr' } },
// Remove key and add new key.
{ refValue: { foo: 'bar' }, newValue: { bar: 'baz' } },
])('$refValue can be modified to $newValue by RefStateEditor.set', ({ refValue, newValue }) => {
editor.set(refValue as any, newValue)
expect(refValue).toEqual(newValue)
})
})
2 changes: 1 addition & 1 deletion packages/devtools-kit/src/core/component/state/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class StateEditor {
}
}

class RefStateEditor {
export class RefStateEditor {
set(ref: Ref<any>, value: any): void {
if (isRef(ref)) {
ref.value = value
Expand Down

0 comments on commit c6a7404

Please sign in to comment.