Skip to content

Commit e77a45a

Browse files
Correcting test in yarn context
1 parent a2809c5 commit e77a45a

File tree

4 files changed

+3080
-2572
lines changed

4 files changed

+3080
-2572
lines changed

tests/unit/helper/setup.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
window.ShadowRoot = Object;
2+
3+
function normalizeHTML(wrapper) {
4+
return wrapper.html().replace(/(\r\n|\n)/gm, "").replace(/>(\s)+</gm, "><");
5+
};
6+
7+
function expectHTML(wrapper, expected) {
8+
const htmlStripped = normalizeHTML(wrapper);
9+
expect(htmlStripped).toEqual(expected);
10+
}
11+
12+
export {
13+
expectHTML,
14+
normalizeHTML
15+
}

tests/unit/vuedraggable.integrated.spec.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mount, config } from "@vue/test-utils";
22
config.global.stubs["transition-group"] = false;
33
import Sortable from "sortablejs";
4+
import { expectHTML } from "./helper/setup"
45

56
jest.genMockFromModule("sortablejs");
67
jest.mock("sortablejs");
@@ -41,15 +42,6 @@ const expectedDomComponent = expectedDomWithWrapper(
4142
' class="fake-root" id="my-id"'
4243
);
4344

44-
function normalizeHTML(wrapper) {
45-
return wrapper.html();
46-
}
47-
48-
function expectHTML(wrapper, expected) {
49-
const htmlStripped = normalizeHTML(wrapper);
50-
expect(htmlStripped).toEqual(expected);
51-
}
52-
5345
describe.each([
5446
["draggable with list", DraggableWithList, expectedDomNoTransition, "span"],
5547
["draggable with model", DraggableWithModel, expectedDomNoTransition, "span"],

tests/unit/vuedraggable.spec.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { mount, config } from "@vue/test-utils";
1+
import { mount } from "@vue/test-utils";
22
import Sortable from "sortablejs";
3+
import { expectHTML, normalizeHTML } from "./helper/setup"
34
jest.mock("sortablejs");
45
const SortableFake = {
56
destroy: jest.fn(),
@@ -25,15 +26,6 @@ const initialRender = `<div><header></header><div data-draggable="true">a</div><
2526
const initialRenderRaw = `<div><div data-draggable="true">a</div><div data-draggable="true">b</div><div data-draggable="true">c</div></div>`;
2627
const initialRenderTransition = `<transition-group-stub><div data-draggable="true">a</div><div data-draggable="true">b</div><div data-draggable="true">c</div></transition-group-stub>`;
2728

28-
function normalizeHTML(wrapper) {
29-
return wrapper.html();
30-
}
31-
32-
function expectHTML(wrapper, expected) {
33-
const htmlStripped = normalizeHTML(wrapper);
34-
expect(htmlStripped).toEqual(expected);
35-
}
36-
3729
function getEvent(name) {
3830
return Sortable.mock.calls[0][1][name];
3931
}
@@ -45,7 +37,7 @@ function resetMocks() {
4537
}
4638

4739
describe("draggable.vue when initialized with list", () => {
48-
beforeEach(() => {
40+
beforeEach(() => {
4941
resetMocks();
5042

5143
items = ["a", "b", "c"];
@@ -792,7 +784,7 @@ describe("draggable.vue when initialized with list", () => {
792784
});
793785

794786
it("updates the rendered elements", () => {
795-
expect(wrapper.html()).toEqual(updatedRender);
787+
expectHTML(wrapper, updatedRender);
796788
});
797789
});
798790

0 commit comments

Comments
 (0)