MCPcopy Index your code
hub / github.com/immerjs/immer / runBaseTest

Function runBaseTest

__tests__/base.js:55–3923  ·  view source on GitHub ↗
(
	name,
	autoFreeze,
	useStrictShallowCopy,
	useListener,
	useArrayMethods = false
)

Source from the content-addressed store, hash-verified

53class Foo {}
54
55function runBaseTest(
56 name,
57 autoFreeze,
58 useStrictShallowCopy,
59 useListener,
60 useArrayMethods = false
61) {
62 const listener = useListener ? function () {} : undefined
63
64 const {produce, produceWithPatches} = createPatchedImmer({
65 autoFreeze,
66 useStrictShallowCopy
67 })
68
69 // When `useListener` is true, append a function to the arguments of every
70 // uncurried `produce` call in every test. This makes tests easier to read.
71 function createPatchedImmer(options) {
72 const immer = new Immer(options)
73
74 const {produce} = immer
75 immer.produce = function (...args) {
76 return typeof args[1] === "function" && args.length < 3
77 ? produce(...args, listener)
78 : produce(...args)
79 }
80
81 return immer
82 }
83
84 describe(`base functionality - ${name}`, () => {
85 let baseState
86 let origBaseState
87
88 beforeEach(() => {
89 origBaseState = baseState = createBaseState()
90
91 // Allow running our tests with and without the array method plugin
92 if (useArrayMethods) {
93 enableArrayMethods()
94 } else {
95 clearPlugin(PluginArrayMethods)
96 }
97 })
98
99 it("returns the original state when no changes are made", () => {
100 const nextState = produce(baseState, s => {
101 expect(s.aProp).toBe("hi")
102 expect(s.anObject.nested).toMatchObject({yummie: true})
103 })
104 expect(nextState).toBe(baseState)
105 })
106
107 it("does structural sharing", () => {
108 const random = Math.random()
109 const nextState = produce(baseState, s => {
110 s.aProp = random
111 })
112 expect(nextState).not.toBe(baseState)

Callers 1

base.jsFile · 0.70

Calls 15

enableArrayMethodsFunction · 0.85
clearPluginFunction · 0.85
createTestDataFunction · 0.85
isDraftFunction · 0.85
isEnumerableFunction · 0.85
expectRevokedFunction · 0.85
enumerableOnlyFunction · 0.85
originalFunction · 0.85
testObjectTypesFunction · 0.85
testLiteralTypesFunction · 0.85
initialStateFactoryFunction · 0.85
firstFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…