Skip to content

Commit

Permalink
fix unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
catFever committed Apr 11, 2022
1 parent 564cbd1 commit b3f9044
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/setup/useDragAndDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ export default function useDragAndDrop(cmn: IUseCommon, props: INodeProps): {} {
});

const getDataTransfer = (evt: DragEvent) : string | object | null => {
if (!evt.dataTransfer) return null;
if (!evt || !evt.dataTransfer) return null;
const jsonPayload = evt.dataTransfer.getData("application/json");
if (jsonPayload) return JSON.parse(jsonPayload);
return evt.dataTransfer.getData("text/plain");
};

const isExternalSrc = (evt: DragEvent) : boolean => {
return evt.dataTransfer?.items?.length > 0;
return evt?.dataTransfer?.items?.length > 0;
};

const dragstart = (evt: DragEvent): void => {
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/useDragAndDrop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ describe("test use Drag and Drop", () => {
wrapper: wrapper.value
};
fakeContext = {
dataTransfer: null,
dragged: fakeDragged,
target: fakeTarget
target: fakeTarget,
evt: undefined,
external: false
};
props = {
parentId: ref(null)
Expand Down

0 comments on commit b3f9044

Please sign in to comment.