HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //var/www/design.system/node_modules/memoizerific/tests/null-args.js
var Memoizerific = require('../src/memoizerific');

describe("null args", () => {
	var memoizedFn,
		arg1 = null,
		arg2 = undefined,
		arg3 = NaN; // important to test since NaN does not equal NaN

	beforeEach(function() {
		memoizedFn = Memoizerific(50)(function(arg1, arg2, arg3) {
			return '';
		});
		memoizedFn(arg1, arg2, arg3);
	});

	it("should be map or similar", () => { expect(memoizedFn.cache instanceof Map).toEqual(process.env.FORCE_SIMILAR_INSTEAD_OF_MAP !== 'true'); });

	it("should not be memoized", () => {
		expect(memoizedFn.wasMemoized).toEqual(false);
		expect(memoizedFn.lru.length).toEqual(1);
	});

	it("should be memoized", () => {
		memoizedFn(arg1, arg2, arg3);
		expect(memoizedFn.wasMemoized).toEqual(true);
		expect(memoizedFn.lru.length).toEqual(1);
	});

	it("should have multiple cached items", () => {
		memoizedFn(arg1, arg2, arg3);
		expect(memoizedFn.wasMemoized).toEqual(true);
		memoizedFn(arg1, arg2, 1);
		expect(memoizedFn.wasMemoized).toEqual(false);
		expect(memoizedFn.lru.length).toEqual(2);
	});

	it("should not confuse undefined and null", () => {
		memoizedFn(arg2, arg1, arg3);
		expect(memoizedFn.wasMemoized).toEqual(false);
		expect(memoizedFn.lru.length).toEqual(2);
	});
});