|
1 | | -import { create, original, current, apply } from '../src'; |
| 1 | +import { create, original, current, apply, isDraftable, isDraft } from '../src'; |
2 | 2 | import { PROXY_DRAFT } from '../src/constant'; |
3 | 3 |
|
4 | 4 | test('check object type', () => { |
@@ -2129,3 +2129,41 @@ test('check Primitive type with returning, patches, freeze and async', async () |
2129 | 2129 | ]); |
2130 | 2130 | } |
2131 | 2131 | }); |
| 2132 | + |
| 2133 | +test('base isDraft()', () => { |
| 2134 | + const baseState = { |
| 2135 | + date: new Date(), |
| 2136 | + list: [{ text: 'todo' }], |
| 2137 | + }; |
| 2138 | + |
| 2139 | + const state = create(baseState, (draft) => { |
| 2140 | + expect(isDraft(draft.date)).toBeFalsy(); |
| 2141 | + expect(isDraft(draft.list)).toBeTruthy(); |
| 2142 | + }); |
| 2143 | +}) |
| 2144 | + |
| 2145 | +test('base isDraftable()', () => { |
| 2146 | + const baseState = { |
| 2147 | + date: new Date(), |
| 2148 | + list: [{ text: 'todo' }], |
| 2149 | + }; |
| 2150 | + |
| 2151 | + expect(isDraftable(baseState.date)).toBeFalsy(); |
| 2152 | + expect(isDraftable(baseState.list)).toBeTruthy(); |
| 2153 | +}); |
| 2154 | + |
| 2155 | +test('base isDraftable() with option', () => { |
| 2156 | + const baseState = { |
| 2157 | + date: new Date(), |
| 2158 | + list: [{ text: 'todo' }], |
| 2159 | + }; |
| 2160 | + |
| 2161 | + expect( |
| 2162 | + isDraftable(baseState.date, { |
| 2163 | + mark: (target, { immutable }) => { |
| 2164 | + if (target instanceof Date) return immutable; |
| 2165 | + }, |
| 2166 | + }) |
| 2167 | + ).toBeTruthy(); |
| 2168 | + expect(isDraftable(baseState.list)).toBeTruthy(); |
| 2169 | +}); |
0 commit comments