Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

test window.location.reload() jest

describe("test window location's reload function", () => {
  const original = window.location;

  const reloadFn = () => {
    window.location.reload(true);
  };

  beforeAll(() => {
    Object.defineProperty(window, 'location', {
      configurable: true,
      value: { reload: jest.fn() },
    });
  });

  afterAll(() => {
    Object.defineProperty(window, 'location', { configurable: true, value: original });
  });

  it('mocks reload function', () => {
    expect(jest.isMockFunction(window.location.reload)).toBe(true);
  });

  it('calls reload function', () => {
    reloadFn(); // as defined above..
    expect(window.location.reload).toHaveBeenCalled();
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: Key Type 
Javascript :: nestjs allow origin 
Javascript :: axios response.json 
Javascript :: recieve voice channel audio discord.js 
Javascript :: get javascript component position 
Javascript :: how to run a function infinite time in javascript 
Javascript :: findone mongoose 
Javascript :: javascript find the longest string in array 
Javascript :: how to disable strict mode on object in javascript 
Javascript :: Download excel using reactJS 
Javascript :: logic operators in js 
Javascript :: post request with data and headers 
Javascript :: call multiple functions onclick react 
Javascript :: read json file into array javascript 
Javascript :: vitejs env 
Javascript :: divide symbol javascript 
Javascript :: counting duplicate values javascript 
Javascript :: expres body parser 
Javascript :: see vuex values productin 
Javascript :: active-class router-link 
Javascript :: javscript ajax request gmt header 
Javascript :: indexof method 
Javascript :: without refresh update url in js 
Javascript :: Find duplicate or repeat elements in js array 
Javascript :: js nuxt read/set cookie 
Javascript :: loop through nested json object typescript 
Javascript :: express.js get params 
Javascript :: js how to calculate factorial 
Javascript :: jquery templates 
Javascript :: multiple export in react 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =