diff --git a/src/webui/components/Search/index.js b/src/webui/components/Search/index.js index df77b5cc8..7fcc752ab 100644 --- a/src/webui/components/Search/index.js +++ b/src/webui/components/Search/index.js @@ -24,7 +24,7 @@ const CONSTANTS = { ABORT_ERROR: 'AbortError', }; -class Search extends Component { +export class Search extends Component { requestList: Array; constructor(props: IProps) { diff --git a/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap b/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap index a751d01c8..022e2a4f1 100644 --- a/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap +++ b/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should load the component with packages 1`] = `""`; +exports[` component should load the component with packages 1`] = `""`; diff --git a/test/unit/webui/components/search.spec.js b/test/unit/webui/components/search.spec.js index 00913447a..a1571efe5 100644 --- a/test/unit/webui/components/search.spec.js +++ b/test/unit/webui/components/search.spec.js @@ -6,7 +6,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import Search from '../../../../src/webui/components/Search/index'; +import { Search } from '../../../../src/webui/components/Search/index'; const SEARCH_FILE_PATH = '../../../../src/webui/components/Search/index'; const API_FILE_PATH = '../../../../src/webui/utils/api'; @@ -121,7 +121,7 @@ describe(' component: mocks specific tests ', () => { }, })); - const Search = require(SEARCH_FILE_PATH).default; + const Search = require(SEARCH_FILE_PATH).Search; const component = mount(); component.setState({ search: 'verdaccio' }); const { handleFetchPackages } = component.instance(); @@ -138,7 +138,7 @@ describe(' component: mocks specific tests ', () => { jest.doMock(API_FILE_PATH, () => ({ request: jest.fn(() => Promise.reject(apiResponse)) })); - const Search = require(SEARCH_FILE_PATH).default; + const Search = require(SEARCH_FILE_PATH).Search; const component = mount(); component.setState({ search: 'verdaccio' }); const { handleFetchPackages } = component.instance(); @@ -159,7 +159,7 @@ describe(' component: mocks specific tests ', () => { }, })); - const Search = require(SEARCH_FILE_PATH).default; + const Search = require(SEARCH_FILE_PATH).Search; const component = mount(); component.setState({ search: 'verdaccio' }); const { handleFetchPackages } = component.instance(); @@ -175,20 +175,19 @@ describe(' component: mocks specific tests ', () => { jest.doMock(URL_FILE_PATH, () => ({ getDetailPageURL })); const suggestionValue = []; - const Search = require(SEARCH_FILE_PATH).default; - const component = mount(); + const Search = require(SEARCH_FILE_PATH).Search; + const pushHandler = jest.fn(); + const component = mount(); const { handleClickSearch } = component.instance(); // click handleClickSearch(event, { suggestionValue, method: 'click' }); expect(event.stopPropagation).toHaveBeenCalled(); - expect(getDetailPageURL).toHaveBeenCalledWith(suggestionValue); - expect(window.location.assign).toHaveBeenCalledWith('detail/page/url'); + expect(pushHandler).toHaveBeenCalledTimes(1); // return key handleClickSearch(event, { suggestionValue, method: 'enter' }); expect(event.stopPropagation).toHaveBeenCalled(); - expect(getDetailPageURL).toHaveBeenCalledWith(suggestionValue); - expect(window.location.assign).toHaveBeenCalledWith('detail/page/url'); + expect(pushHandler).toHaveBeenCalledTimes(2); }); });