edited tests for no fail and added new Tag test

This commit is contained in:
Lukas Heiligenbrunner 2020-06-23 23:13:14 +02:00
parent 89153b5da9
commit 4ac21506f3
4 changed files with 31 additions and 4 deletions

View File

@ -22,7 +22,7 @@ describe('<Preview/>', function () {
const wrapper = shallow(<Preview/>);
wrapper.setProps({
viewbinding: {
showVideo: () => {
changeRootElement: () => {
func()
}
}

View File

@ -5,6 +5,14 @@ import "@testing-library/jest-dom"
import {shallow} from 'enzyme'
describe('<Tag/>', function () {
function prepareFetchApi(response) {
const mockJsonPromise = Promise.resolve(response);
const mockFetchPromise = Promise.resolve({
json: () => mockJsonPromise,
});
return (jest.fn().mockImplementation(() => mockFetchPromise));
}
it('renders without crashing ', function () {
const wrapper = shallow(<Tag>test</Tag>);
wrapper.unmount();
@ -14,4 +22,22 @@ describe('<Tag/>', function () {
const wrapper = shallow(<Tag>test</Tag>);
expect(wrapper.children().text()).toBe("test");
});
it('click event triggered and setvideo callback called', done => {
global.fetch = prepareFetchApi({});
const func = jest.fn();
const wrapper = shallow(<Tag
contentbinding={func}>test</Tag>);
wrapper.simulate("click");
process.nextTick(() => {
// state to be set correctly with response
expect(func).toBeCalledTimes(1);
global.fetch.mockClear();
done();
});
});
});

View File

@ -1,4 +1,4 @@
import {shallow} from "enzyme";
import {shallow, mount} from "enzyme";
import React from "react";
import HomePage from "./HomePage";
import VideoContainer from "../../elements/VideoContainer/VideoContainer";
@ -23,7 +23,8 @@ describe('<HomePage/>', function () {
});
it('ckeck default tag click events', function () {
const wrapper = shallow(<HomePage/>);
// todo mount bad here maybe delete this test
const wrapper = mount(<HomePage/>);
global.fetch = prepareFetchApi({});
expect(global.fetch).toBeCalledTimes(0);

View File

@ -99,7 +99,7 @@ describe('<Player/>', function () {
wrapper.setProps({
viewbinding: {
hideVideo: () => {
returnToLastElement: () => {
func()
}
}