Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mock javascript function

// ---- comp.js ----
import * as React from 'react';
import * as comp from './comp';

export const remove = () => {
  // ...do something
}

export const RemoveButton = (props) => (
  <div onClick={() => comp.remove()}>
    Remove
  </div>
);


// ---- comp.test.js ----
import * as React from 'react';
import { shallow } from 'enzyme';

import * as comp from './comp';

describe('removeButton', () => {
  it('should call remove on click', () => {
    const mock = jest.spyOn(comp, 'remove');
    mock.mockImplementation(() => {});
    const component = shallow(<comp.RemoveButton />);
    component.find('div').simulate('click');
    expect(mock).toHaveBeenCalled();
    mock.mockRestore();
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: How to add js file to a site through url 
Javascript :: module 
Javascript :: jqueyr get parent 
Javascript :: create your own programming language in javascript 
Javascript :: add select option jquery 
Javascript :: js electron setup 
Javascript :: save to local storage 
Javascript :: sessionstorage in js 
Javascript :: error: Error: Unable to resolve module `crypto` from `node_modulescrypto-jscore.js`: crypto could not be found within the project. 
Javascript :: addeventlistener 
Javascript :: js detect end of array 
Javascript :: break out of map javascript 
Javascript :: gsap react 
Javascript :: javascript greater than or equal to 
Javascript :: how to make popup modal in jquery with example 
Javascript :: What are "res" and "req" parameters in Express functions 
Javascript :: leaflet js 
Javascript :: scss variables in react 
Javascript :: fetch in vue 3 
Javascript :: query selector js 
Javascript :: javascript set query parameters in url 
Javascript :: jq append value to array 
Javascript :: max array 
Javascript :: array.filter 
Javascript :: firebase realtime database javascript 
Javascript :: firebase timestamp to date react 
Javascript :: aws lambda function setup for node js 
Javascript :: css in js material ui 
Javascript :: datatable ajax reload 
Javascript :: javascript classes 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =