test: remove old recursion tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
These tests handle no edge cases that arent already handled in "__tests__/base.js"
authored by aleclarson · committed by Alec Larson · parent d9b91d5 · Browse files · 1 file·+0 added−187 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+0 added−187 removed
- tests:+0 added−187 removed
Provenance
- Commit
76d4e0b- Tree
603ec23- Author
aleclarson <alec.stanford.larson@gmail.com>- Committer
Alec Larson <alec.stanford.larson@gmail.com>- Parent
d9b91d5
1 file changed+0 added−187 removed
deleted:__tests__/recursive.js-187 removed
1-"use strict"2-import produce, {setUseProxies} from "../src/index"3-import {isArray, isPlainObject, isString, keys, trim} from "lodash"4-5-const nonPlainObject = () => {}6-7-runTests("proxy", true)8-runTests("es5", false)9-10-function runTests(name, useProxies) {11- describe("recursive - " + name, () => {12- setUseProxies(useProxies)13-14- const testCases = [15- {16- title: "in a simple non-recursive case",17- recursiveTransform: recursivelyTrimStrings,18- baseState: " hello ",19- desiredState: "hello"20- },21- {22- title: "in a simple non-recursive unchanged case",23- recursiveTransform: recursivelyTrimStrings,24- baseState: "hello",25- desiredState: "hello"26- },27- {28- title: "if baseState is an object that does not change",29- recursiveTransform: recursivelyTrimStrings,30- baseState: {31- a: 1,32- b: "test",33- c: {34- a: [true, null, false, "test"],35- b: 136- }37- }38- },39- {40- title: "if baseState is an array does not change",41- recursiveTransform: recursivelyTrimStrings,42- baseState: [true, null, false, "test"]43- },44- {45- title: "when all leafs are changing",46- recursiveTransform: recursivelyTrimStrings,47- baseState: {48- x: " hello ",49- arr: [50- "world ",51- 42,52- " !!!",53- {54- x: 42,55- test: "true "56- }57- ]58- },59- desiredState: {60- x: "hello",61- arr: [62- "world",63- 42,64- "!!!",65- {66- x: 42,67- test: "true"68- }69- ]70- }71- },72- {73- title: "when there is an unchanged leaf array",74- recursiveTransform: recursivelyTrimStrings,75- baseState: {76- x: " hello ",77- arr: [1, 2, 3]78- },79- desiredState: {80- x: "hello",81- arr: [1, 2, 3]82- }83- },84- {85- title:86- "when there is an unchanged leaf object in an unchanged array",87- recursiveTransform: recursivelyTrimStrings,88- baseState: {89- arr: [90- "!!!",91- {92- x: 42,93- y: "test"94- }95- ]96- },97- desiredState: {98- arr: [99- "!!!",100- {101- x: 42,102- y: "test"103- }104- ]105- }106- },107- {108- title:109- "when there is an unchanged leaf object in a changed array",110- recursiveTransform: recursivelyTrimStrings,111- baseState: {112- arr: [113- " !!!",114- {115- x: 42,116- y: "test"117- }118- ]119- },120- desiredState: {121- arr: [122- "!!!",123- {124- x: 42,125- y: "test"126- }127- ]128- }129- },130- {131- title:132- "when there is an unchanged leaf array in a changed object",133- recursiveTransform: recursivelyTrimStrings,134- baseState: {135- test: "!!! ",136- arr: [1, 2, 3]137- },138- desiredState: {139- test: "!!!",140- arr: [1, 2, 3]141- }142- },143- {144- title: "when there non-plain objects",145- recursiveTransform: recursivelyTrimStrings,146- baseState: {147- a: [nonPlainObject, 1],148- b: nonPlainObject149- }150- }151- ]152-153- testCases154- .slice(0, 9)155- .forEach(({title, baseState, desiredState, recursiveTransform}) => {156- it(`should not leave drafts ${title}`, () => {157- const next = recursiveTransform(baseState)158- if (desiredState) {159- // an exception is thrown during deep comparison if any of the drafts is not finalized160- expect(next).toEqual(desiredState)161- } else {162- expect(next).toBe(baseState)163- }164- })165- })166- })167-}168-169-function recursivelyTrimStrings(source) {170- if (isString(source)) {171- return trim(source)172- } else if (isArray(source)) {173- return produce(source, draft =>174- draft.forEach((el, i) => {175- const v = recursivelyTrimStrings(el)176- draft[i] = v177- })178- )179- } else if (isPlainObject(source)) {180- return produce(source, draft => {181- keys(draft).forEach(key => {182- draft[key] = recursivelyTrimStrings(draft[key])183- })184- })185- }186- return source187-}