PluginProbe
Extendify / 3.0.5
Extendify v3.0.5
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Shared / utils / __tests__ / get-url-parameter.test.js

get-url-parameter.test.js in Extendify 3.0.5, at src/Shared/utils/__tests__/get-url-parameter.test.js

51 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { getUrlParameter } from '@shared/utils/get-url-parameter';
2
3 describe('getUrlParameter', () => {
4 beforeEach(() => {
5 jest.restoreAllMocks();
6 window.history.pushState({}, '', '/');
7 });
8
9 it('should return null if parameter does not exist', () => {
10 window.history.pushState({}, '', '/?param1=value1');
11 expect(getUrlParameter('param2')).toBeNull();
12 });
13
14 it('should return the correct parameter value from URL', () => {
15 window.history.pushState({}, '', '/?param1=value1&param2=value2');
16 expect(getUrlParameter('param1')).toBe('value1');
17 expect(getUrlParameter('param2')).toBe('value2');
18 });
19
20 it('should cleanup the parameter in url after use', () => {
21 window.history.pushState({}, '', '/?param1=Hello%20World');
22 const replaceStateSpy = jest.spyOn(window.history, 'replaceState');
23
24 getUrlParameter('param1');
25
26 expect(replaceStateSpy).toHaveBeenCalledWith({}, document.title, '/');
27 });
28
29 it('should NOT cleanup the parameter in url if cleanUrl is false', () => {
30 window.history.pushState({}, '', '/?param1=Hello%20World');
31 const replaceStateSpy = jest.spyOn(window.history, 'replaceState');
32
33 getUrlParameter('param1', false);
34
35 expect(replaceStateSpy).not.toHaveBeenCalled();
36 });
37
38 it('should NOT affect other parameters in url when cleanup', () => {
39 window.history.pushState({}, '', '/?param1=Hello%20World&other=keep-it');
40 const replaceStateSpy = jest.spyOn(window.history, 'replaceState');
41
42 getUrlParameter('param1');
43
44 expect(replaceStateSpy).toHaveBeenCalledWith(
45 {},
46 document.title,
47 '/?other=keep-it',
48 );
49 });
50 });
51