Skip to content
Myr

original.js

This file

Path

__tests__/original.js

49 lines · 1.5 KiB · JavaScript

Last changed by

Merge pull request #179 from RichieAHB/rahb/add-originalMichel Weststratebefore adoptionf8479c2

History of this file

Take it

Merge pull request #179 from RichieAHB/rahb/add-originalMichel Weststratebefore adoptionf8479c2

lines 1–49why, one step back
1"use strict"
2import produce, {original, setUseProxies} from "../src/immer"34describe("original", () => {5 const baseState = {6 a: [],7 b: {}8 }910 it("should return the original from the draft", () => {11 setUseProxies(true)1213 produce(baseState, draftState => {14 expect(original(draftState)).toBe(baseState)15 expect(original(draftState.a)).toBe(baseState.a)16 expect(original(draftState.b)).toBe(baseState.b)17 })1819 setUseProxies(false)2021 produce(baseState, draftState => {22 expect(original(draftState)).toBe(baseState)23 expect(original(draftState.a)).toBe(baseState.a)24 expect(original(draftState.b)).toBe(baseState.b)25 })26 })2728 it("should return the original from the proxy", () => {29 produce(baseState, draftState => {30 expect(original(draftState)).toBe(baseState)31 expect(original(draftState.a)).toBe(baseState.a)32 expect(original(draftState.b)).toBe(baseState.b)33 })34 })3536 it("should return undefined for new values on the draft", () => {37 produce(baseState, draftState => {38 draftState.c = {}39 draftState.d = 340 expect(original(draftState.c)).toBeUndefined()41 expect(original(draftState.d)).toBeUndefined()42 })43 })4445 it("should return undefined for an object that is not proxied", () => {46 expect(original({})).toBeUndefined()47 expect(original(3)).toBeUndefined()48 })49})