enzyme#mount JavaScript Examples
The following examples show how to use
enzyme#mount.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.test.js From acy-dex-interface with MIT License | 6 votes |
describe('AvatarList', () => {
it('renders all items', () => {
const wrapper = mount(<AvatarList>{renderItems(4)}</AvatarList>);
expect(wrapper.find('AvatarList').length).toBe(1);
expect(wrapper.find('Item').length).toBe(4);
expect(wrapper.findWhere(node => node.key() === 'exceed').length).toBe(0);
});
it('renders max of 3 items', () => {
const wrapper = mount(<AvatarList maxLength={3}>{renderItems(4)}</AvatarList>);
expect(wrapper.find('AvatarList').length).toBe(1);
expect(wrapper.find('Item').length).toBe(3);
expect(wrapper.findWhere(node => node.key() === 'exceed').length).toBe(1);
});
});
Example #2
Source File: UpperContainer.test.js From Oud with MIT License | 6 votes |
describe("artist from user view component: testing upper part", () => {
let component;
beforeEach(() => {
component = setup();
});
it("redndering the whole upper components", () => {
expect(component.find(".artist-user").exists()).toBe(true);
});
it("redndering the play button", () => {
expect(component.find(".play-artist").exists()).toBe(true);
});
it("redndering the follow button", () => {
expect(
component.find("#artist-follow-button-upperContainer").exists()
).toBe(true);
});
it("redndering the option dropdown", () => {
expect(component.find(".artist-options-dropdown").exists()).toBe(true);
});
it("redndering the option dropdown", () => {
const wrapper = mount(
<Options
artistId={"1"}
followStatus={true}
handleFollowClick={() => {}}
/>
);
expect(wrapper.find(".artist-ellipsis-container").exists()).toBe(true);
});
});
Example #3
Source File: InfiniteScrollImage.test.js From viade_en2b with MIT License | 6 votes |
/////////////////////////
test("Test State", () => {
const scroll = mount(
<InfiniteScrollImage
content={[
{ name: "hola", dateAttached: new Date("January 22, 2012 06:32:32") },
]}
/>
);
scroll.setState({ hasMore: false });
expect(scroll.state().hasMore).toBe(false);
});
Example #4
Source File: route-card.test.js From viade_es2a with BSD 2-Clause "Simplified" License | 6 votes |
describe('RouteCard', () => {
afterAll(cleanup);
let wrapper;
beforeEach(() => {
wrapper = mount(
<RouteMapContext.Provider value={{ selectedRoute: route.id, myRoutes: false }}>
<RouteCard {...{ route }} />
</RouteMapContext.Provider>
);
});
it('renders without crashing', () => {
expect(wrapper).toBeTruthy();
});
it('renders on creation', () => {
expect(wrapper.find('.title_Test')).toBeDefined();
expect(wrapper.find('.date_Test')).toBeDefined();
expect(wrapper.find('.rwrapper')).toBeDefined();
expect(wrapper.find('.title_Test')).toHaveLength(1);
expect(wrapper.find('.date_Test')).toHaveLength(1);
expect(wrapper.find('.rwrapper')).toHaveLength(3);
});
it('route shown correctly', () => {
expect(wrapper.find('.title_Test')).toBeDefined();
expect(wrapper.find('.date_Test')).toBeDefined();
expect(wrapper.find('.rwrapper')).toBeDefined();
var m = moment(route.date).fromNow();
expect(wrapper.find('.title_Test').text()).toContain(route.name);
expect(wrapper.find('.date_Test').text()).toContain(m);
});
});
Example #5
Source File: body.test.js From Classroom-Bot with MIT License | 6 votes |
describe("routes using memory router", () => {
it("should show Main component for / router (using memory router)", () => {
const component = mount(
<MemoryRouter initialentries="{['/']}">
<Main />
</MemoryRouter>
);
expect(component.find(Main)).toHaveLength(1);
});
});
Example #6
Source File: Footer.test.js From Merch-Dropper-fe with MIT License | 6 votes |
it("expect to render Footer component", () => {
const wrapper = mount(
<Provider store={store}>
<MemoryRouter initialEntries={["/"]}>
<Footer />
</MemoryRouter>
</Provider>
);
const div = wrapper.find("div").get(0);
const ul = wrapper.find("ul a");
expect(wrapper).toBeTruthy();
expect(div.props.style).toHaveProperty("display", "block");
expect(ul).toHaveLength(2);
expect(ul.containsMatchingElement(<a>Home</a>)).toBeTruthy();
expect(ul.containsMatchingElement(<a>Store</a>)).toBeTruthy();
});
Example #7
Source File: PostVideoModal.test.js From video-journal-for-teams-fe with MIT License | 6 votes |
describe("<PostVideoModal>", () => {
let store;
let wrapper;
beforeAll(() => {
store = mockStore({
User: {
videoStream: {
raw: null,
},
},
});
});
afterEach(() => {
wrapper.unmount();
});
test("should render self without error", () => {
wrapper = mount(
<Provider store={store}>
<PostVideoModal />
</Provider>
);
});
test("should render a <Modal> component", () => {
wrapper = mount(
<Provider store={store}>
<PostVideoModal />
</Provider>
);
expect(wrapper.exists(Modal)).toBe(true);
});
});
Example #8
Source File: AnswerForm.test.jsx From FEC with MIT License | 6 votes |
describe('Answer Form', () => {
test('The modal opens and closes', () => {
wrapper.find('button.qaButton').at(1).simulate('click');
expect(wrapper.state().modal).toBe(true);
wrapper.find('.close').simulate('click')
expect(wrapper.state().modal).toBe(false);
});
test('Inputs take text', () => {
const component = mount(<AnswerForm />);
const wrapper = mount(<QuestionOptions />);
wrapper.find('button.qaButton').at(1).simulate('click');
wrapper.find('.qInput').at(0).simulate('change', {target: {value: 'Yes'}});
wrapper.find('.qInput').at(1).simulate('change', {target: {value: 'Bob'}});
wrapper.find('.qInput').at(2).simulate('change', {target: {value: '[email protected]'}});
wrapper.find('.submitAnswer').simulate('click');
component.setState({
answer: 'Yes',
qInput: 'Bob',
email: '[email protected]'
})
expect(component.state().form.answer).toBe("");
});
});
Example #9
Source File: Chart.test.jsx From Corona-tracker with MIT License | 6 votes |
describe('Chart', () => {
it('should render a Chart component ', () => {
const store = mockStore({
observationsReducer: mockObservationsReducerState,
onboardingReducer: mockOnboardReducerState,
});
window.HTMLCanvasElement.prototype.getContext = () => {};
const wrapper = mount(
<Provider store={store}>
<Chart chartType="test" />
</Provider>
);
expect(wrapper.find('Chart')).toMatchSnapshot();
});
});
Example #10
Source File: create-theme-listener.test.js From cybsec with GNU Affero General Public License v3.0 | 6 votes |
test(`themeListener without ThemeProvider`, t => {
const themeListener = createThemeListener();
const Trap = getTrap(themeListener);
t.throws(
() => {
mount(<Trap intercept={() => {}} />);
},
Error,
`themeListener should throw if used without appropriate context`,
);
});
Example #11
Source File: AssignmentSummary.test.js From Spoke with MIT License | 6 votes |
describe("AssignmentSummary text", function t() {
beforeEach(() => {
campaignIsBetweenTextingHours.mockReturnValue(true);
this.summary = mount(
<MuiThemeProvider>
<AssignmentSummary
assignment={getAssignment()}
organizationId={1}
contactCount={getContactCounts({ needsMessage: 1, convo: 0 })}
/>
</MuiThemeProvider>
);
});
test("renders title and html", () => {
// Note: Warren fork does not support ALLOW_SEND_ALL
window.NOT_IN_USA = 0;
window.ALLOW_SEND_ALL = false;
const title = this.summary.find(CardTitle);
expect(title.prop("title")).toBe("New Campaign");
// expect(title.find(CardTitle).prop('subtitle')).toBe('asdf - Jan 31 2018')
const htmlWrapper = this.summary.findWhere(
d => d.length && d.type() === "div" && d.prop("dangerouslySetInnerHTML")
);
expect(htmlWrapper.prop("dangerouslySetInnerHTML")).toEqual({
__html: "yoyo"
});
});
});
Example #12
Source File: useBreakpoint.test.js From pollaris with MIT License | 6 votes |
describe('current', () => {
const CurrentBP = () => {
const { current } = useBreakpoint(theme.screens);
return (<div>{current}</div>);
};
const screensTable = Object.entries({ default: '0px', ...theme.screens });
test.each(screensTable)('returns \'%s\' when screen width is \'%s\'', (bpName, screenWidth) => {
const wrapper = mount(
<ResponsiveContext.Provider value={{ width: parseInt(screenWidth, 10) }}>
<CurrentBP />
</ResponsiveContext.Provider>,
);
expect(wrapper.text()).toBe(bpName);
});
});
Example #13
Source File: example.test.js From Elemento with MIT License | 5 votes |
it('it renders Example element',()=>{
const wrapper = mount(<Example/>);
expect(wrapper.find('.exampleImage')).toMatchSnapshot();
});
Example #14
Source File: GenreCard.test.js From Oud with MIT License | 5 votes |
describe('Genre Card Component', () => {
let component;
beforeEach(() => {
const props = {
item
}
component = setup(props);
})
it('Should render card-container in right way', () => {
const wrapper = findByTestAttr(component, "card-container");
expect(wrapper.length).toBe(1);
});
it('Should render card-container in right way', () => {
const wrapper = findByTestAttr(component, "card");
expect(wrapper.length).toBe(1);
});
it('Should render over layer in right way', () => {
const wrapper = findByTestAttr(component, "overlayer");
expect(wrapper.length).toBe(1);
});
it('Should render playlist image in right way', () => {
const wrapper = findByTestAttr(component, "playlist-image");
expect(wrapper.length).toBe(1);
});
it('Should render playlist title in right way', () => {
const wrapper = findByTestAttr(component, "playlist-title");
expect(wrapper.length).toBe(1);
});
it('Should render playlist link in right way', () => {
const wrapper = findByTestAttr(component, "playlist-link");
expect(wrapper.length).toBe(1);
});
it('Should render playlist inner text in right way', () => {
component.setState({ name: "Hemdan" })
const wrapper = findByTestAttr(component, "playlist-link");
expect(wrapper.text()).toBe(item.name);
});
describe('snapshot test', () => {
it('renders component correctly', () => {
const wrapper = mount(
<MemoryRouter>
<GenreCard.WrappedComponent item={item} />
</MemoryRouter >
)
expect(wrapper).toMatchSnapshot()
});
});
describe('testing prop types', () => {
it('should pass true props', () => {
const result = checkPropTypes(GenreCard.WrappedComponent.propTypes, { ...item }, 'prop', GenreCard.WrappedComponent.name);
expect(result).toBeUndefined();
});
it('should pass false props', () => {
const result = checkPropTypes(GenreCard.WrappedComponent.propTypes, { item: 0 }, 'prop', GenreCard.WrappedComponent.name);
expect(result).toBeDefined();
});
it('should pass false props', () => {
const result = checkPropTypes(GenreCard.WrappedComponent.propTypes, { item: true }, 'prop', GenreCard.WrappedComponent.name);
expect(result).toBeDefined();
});
it('should pass false props', () => {
const result = checkPropTypes(GenreCard.WrappedComponent.propTypes, { item: jest.fn }, 'prop', GenreCard.WrappedComponent.name);
expect(result).toBeDefined();
});
it('should pass false props', () => {
const result = checkPropTypes(GenreCard.WrappedComponent.propTypes, { item: [15] }, 'prop', GenreCard.WrappedComponent.name);
expect(result).toBeDefined();
});
it('should pass false props', () => {
const result = checkPropTypes(GenreCard.WrappedComponent.propTypes, { item: "" }, 'prop', GenreCard.WrappedComponent.name);
expect(result).toBeDefined();
});
})
});
Example #15
Source File: BurgerMenu.test.js From viade_en2b with MIT License | 5 votes |
test("HamburguerDefinedHome", () => {
const temp = mount(<BurgerMenu/>);
expect(temp.find("#home")).toBeDefined();
});