Skip to content

Commit 9f10b90

Browse files
committed
@vue/test-utils 1.0.0
Prior to the 1.0.0 release, @vue/test-utils made a few breaking changes: * The "sync mode" was removed in vuejs/vue-test-utils#1137, meaning that we have to explicitly call nextTick() before checking if something has changed in the DOM * transition is no longer automatically stubbed, we have to create our own transitionStub.
1 parent 2433a60 commit 9f10b90

18 files changed

+87
-40
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"@babel/preset-env": "7.1.6",
147147
"@babel/register": "7.0.0",
148148
"@vue/runtime-dom": "^3.2.47",
149-
"@vue/test-utils": "1.0.0-beta.26",
149+
"@vue/test-utils": "1.0.0",
150150
"autoprefixer": "^9.3.1",
151151
"babel-core": "7.0.0-bridge.0",
152152
"babel-eslint": "^10.0.1",

test/unit/specs/components/alert.spec.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import Alert from "@/elements/Alert.vue"
44
// create an extended `Vue` constructor
55
const localVue = createLocalVue()
66

7+
const transitionStub = () => ({
8+
render: function(h) {
9+
return this.$options._renderChildren
10+
},
11+
})
12+
713
describe("Alert.vue", () => {
814
let wrapper
915

@@ -13,6 +19,9 @@ describe("Alert.vue", () => {
1319
slots: {
1420
default: "Here's some info for you.",
1521
},
22+
stubs: {
23+
transition: transitionStub(),
24+
},
1625
// if props are set here, buttons aren't rendered
1726
// props: {
1827
// dismissible: true,
@@ -25,17 +34,20 @@ describe("Alert.vue", () => {
2534
expect(el.text()).toBe("Here's some info for you.")
2635
})
2736

28-
it("should have a button when dismissible", () => {
37+
it("should have a button when dismissible", async () => {
2938
wrapper.setProps({ dismissible: true })
39+
await localVue.nextTick()
3040
const button = wrapper.find("button")
3141
expect(wrapper.vm.dismissible).toBe(true)
3242
expect(button.is("button")).toBe(true)
3343
})
3444

35-
it("should be dismissible on click", () => {
45+
it("should be dismissible on click", async () => {
3646
wrapper.setProps({ dismissible: true })
47+
await localVue.nextTick()
3748
const button = wrapper.find("button")
3849
button.trigger("click")
50+
await localVue.nextTick()
3951
expect(wrapper.isEmpty()).toBe(true)
4052
})
4153

@@ -54,8 +66,9 @@ describe("Alert.vue", () => {
5466
expect(wrapper.vm.show).toBe(false)
5567
})
5668

57-
it("should hide after 2 seconds when autoclear is true", () => {
69+
it("should hide after 2 seconds when autoclear is true", async () => {
5870
wrapper.setProps({ autoclear: true })
71+
await localVue.nextTick()
5972
const el = wrapper.find(".lux-alert")
6073
expect(wrapper.vm.show).toBe(true)
6174
// wait 3 seconds and see if it's hidden
@@ -64,7 +77,7 @@ describe("Alert.vue", () => {
6477
}, 3000)
6578
})
6679

67-
it("has the expected html structure", () => {
80+
it("has the expected html structure", async () => {
6881
expect(wrapper.element).toMatchSnapshot()
6982
})
7083
})

test/unit/specs/components/banner.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@ describe("Banner.vue", () => {
2222
expect(el.text()).toBe("Here's some info for you.")
2323
})
2424

25-
it("should have a button when dismissible", () => {
25+
it("should have a button when dismissible", async () => {
2626
wrapper.setProps({ dismissible: true })
27+
await localVue.nextTick()
2728
const button = wrapper.find("button")
2829
expect(wrapper.vm.dismissible).toBe(true)
2930
expect(button.is("button")).toBe(true)
3031
})
3132

32-
it("should be dismissible on click", () => {
33+
it("should be dismissible on click", async () => {
3334
wrapper.setProps({ dismissible: true })
35+
await localVue.nextTick()
3436
const button = wrapper.find("button")
3537
button.trigger("click")
38+
await localVue.nextTick()
3639
expect(wrapper.isEmpty()).toBe(true)
3740
})
3841

test/unit/specs/components/datatable.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ describe("DataTable.vue", () => {
8585
expect(wrapper.vm.isRight("right")).toBe(true)
8686
})
8787

88-
it("should show tfoot if summaryLabel is present", () => {
88+
it("should show tfoot if summaryLabel is present", async () => {
8989
wrapper.setProps({ summaryLabel: "Average" })
90+
await localVue.nextTick()
9091
const th = wrapper.find("tfoot th")
9192
expect(th.text()).toBe("Average")
9293
})

test/unit/specs/components/gallery.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ describe("Gallery.vue", () => {
6060
// expect(wrapper.vm.items[0].id).toBe(3)
6161
// })
6262

63-
it("sizes the card correctly", () => {
63+
it("sizes the card correctly", async () => {
6464
wrapper.setProps({ cardPixelWidth: 200 })
65+
await localVue.nextTick()
6566
const card = wrapper.find(".lux-galleryCard")
6667
expect(card.attributes().cardpixelwidth).toBe("200")
6768
})

test/unit/specs/components/gridItem.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ describe("GridItem.vue", () => {
1616
})
1717
})
1818

19-
it("should have the appropriate class to define the columns", () => {
19+
it("should have the appropriate class to define the columns", async () => {
2020
wrapper.setProps({ columns: "lg-9 sm-6" })
21+
await localVue.nextTick()
2122
const gridItem = wrapper.find(".lux-col")
2223
expect(gridItem.is(".lg-9.sm-6")).toBe(true)
2324
})
2425

25-
it("should have the appropriate class to define the vertical alignment", () => {
26+
it("should have the appropriate class to define the vertical alignment", async () => {
2627
wrapper.setProps({ vertical: "start" })
28+
await localVue.nextTick()
2729
const gridItem = wrapper.find(".lux-col")
2830
expect(gridItem.is(".start")).toBe(true)
2931
})

test/unit/specs/components/inputAutocomplete.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ describe("InputAutocomplete.vue", () => {
6161
expect(wrapper.vm.inputValue).toBe("Foo")
6262
})
6363

64-
it("should have a label if passed in", () => {
64+
it("should have a label if passed in", async () => {
6565
expect(wrapper.find("label").exists()).toBe(false)
6666
wrapper.setProps({ label: "Fill in the blank:" })
67+
await localVue.nextTick()
6768
expect(wrapper.find("label").exists()).toBe(true)
6869
expect(wrapper.find("label").text()).toBe("Fill in the blank:")
6970
})

test/unit/specs/components/inputCheckbox.spec.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,26 @@ describe("InputCheckbox.vue", () => {
5454
expect(label.attributes().for).toBe("checkbox-opt2")
5555
})
5656

57-
it("should stack if vertical is true", () => {
57+
it("should stack if vertical is true", async () => {
5858
const checkbox = wrapper.findAll(".lux-checkbox").at(0)
5959
expect(checkbox.classes()).toContain("lux-inline")
6060
wrapper.setProps({ vertical: true })
61+
await localVue.nextTick()
6162
expect(checkbox.classes()).not.toContain("lux-inline")
6263
})
6364

64-
it("should display an errormessage with the proper role when passed in as a prop", () => {
65+
it("should display an errormessage with the proper role when passed in as a prop", async () => {
6566
expect(wrapper.find(".lux-error").exists()).toBe(false)
6667
wrapper.setProps({ errormessage: "Something went wrong." })
68+
await localVue.nextTick()
6769
expect(wrapper.find(".lux-error").exists()).toBe(true)
6870
expect(wrapper.find(".lux-error").attributes().role).toBe("alert")
6971
})
7072

71-
it("should display a legend if groupLabel is passed in as a prop", () => {
73+
it("should display a legend if groupLabel is passed in as a prop", async () => {
7274
expect(wrapper.find("legend").exists()).toBe(false)
7375
wrapper.setProps({ groupLabel: "Multiple choice:" })
76+
await localVue.nextTick()
7477
expect(wrapper.find("legend").exists()).toBe(true)
7578
})
7679

test/unit/specs/components/inputDataList.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ describe("InputText.vue", () => {
4141
expect(Object.prototype.hasOwnProperty.call(emitted, "inputblur")).toBe(true)
4242
})
4343

44-
it("should have a label if passed in", () => {
44+
it("should have a label if passed in", async () => {
4545
expect(wrapper.find("label").exists()).toBe(false)
4646
wrapper.setProps({ label: "Fill in the blank:" })
47+
await localVue.nextTick()
4748
expect(wrapper.find("label").exists()).toBe(true)
4849
expect(wrapper.find("label").text()).toBe("Fill in the blank:")
4950
})
5051

51-
it("should display an errormessage with the proper role when passed in as a prop", () => {
52+
it("should display an errormessage with the proper role when passed in as a prop", async () => {
5253
expect(wrapper.find(".lux-error").exists()).toBe(false)
5354
wrapper.setProps({ errormessage: "Something went wrong." })
55+
await localVue.nextTick()
5456
expect(wrapper.find(".lux-error").exists()).toBe(true)
5557
expect(wrapper.find(".lux-error").attributes().role).toBe("alert")
5658
})

test/unit/specs/components/inputRadio.spec.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,26 @@ describe("InputRadio.vue", () => {
5555
expect(label.attributes().for).toBe("radio-opt2")
5656
})
5757

58-
it("should stack if vertical is true", () => {
58+
it("should stack if vertical is true", async () => {
5959
const radio = wrapper.findAll(".lux-radio").at(0)
6060
expect(radio.classes()).toContain("lux-inline")
6161
wrapper.setProps({ vertical: true })
62+
await localVue.nextTick()
6263
expect(radio.classes()).not.toContain("lux-inline")
6364
})
6465

65-
it("should display an errormessage with the proper role when passed in as a prop", () => {
66+
it("should display an errormessage with the proper role when passed in as a prop", async () => {
6667
expect(wrapper.find(".lux-error").exists()).toBe(false)
6768
wrapper.setProps({ errormessage: "Something went wrong." })
69+
await localVue.nextTick()
6870
expect(wrapper.find(".lux-error").exists()).toBe(true)
6971
expect(wrapper.find(".lux-error").attributes().role).toBe("alert")
7072
})
7173

72-
it("should display a legend if groupLabel is passed in as a prop", () => {
74+
it("should display a legend if groupLabel is passed in as a prop", async () => {
7375
expect(wrapper.find("legend").exists()).toBe(false)
7476
wrapper.setProps({ groupLabel: "Multiple choice:" })
77+
await localVue.nextTick()
7578
expect(wrapper.find("legend").exists()).toBe(true)
7679
})
7780

test/unit/specs/components/inputSelect.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ describe("InputSelect.vue", () => {
4646
expect(Object.prototype.hasOwnProperty.call(emitted, "inputblur")).toBe(true)
4747
})
4848

49-
it("should have a label if passed in", () => {
49+
it("should have a label if passed in", async () => {
5050
expect(wrapper.find("label").exists()).toBe(false)
5151
wrapper.setProps({ label: "Multiple choice:" })
52+
await localVue.nextTick()
5253
expect(wrapper.find("label").exists()).toBe(true)
5354
expect(wrapper.find("label").text()).toBe("Multiple choice:")
5455
})
5556

56-
it("should display an errormessage with the proper role when passed in as a prop", () => {
57+
it("should display an errormessage with the proper role when passed in as a prop", async () => {
5758
expect(wrapper.find(".lux-error").exists()).toBe(false)
5859
wrapper.setProps({ errormessage: "Something went wrong." })
60+
await localVue.nextTick()
5961
expect(wrapper.find(".lux-error").exists()).toBe(true)
6062
expect(wrapper.find(".lux-error").attributes().role).toBe("alert")
6163
})

test/unit/specs/components/inputText.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ describe("InputText.vue", () => {
4141
expect(Object.prototype.hasOwnProperty.call(emitted, "inputblur")).toBe(true)
4242
})
4343

44-
it("should have a label if passed in", () => {
44+
it("should have a label if passed in", async () => {
4545
expect(wrapper.find("label").exists()).toBe(false)
4646
wrapper.setProps({ label: "Fill in the blank:" })
47+
await localVue.nextTick()
4748
expect(wrapper.find("label").exists()).toBe(true)
4849
expect(wrapper.find("label").text()).toBe("Fill in the blank:")
4950
})
5051

51-
it("should display an errormessage with the proper role when passed in as a prop", () => {
52+
it("should display an errormessage with the proper role when passed in as a prop", async () => {
5253
expect(wrapper.find(".lux-error").exists()).toBe(false)
5354
wrapper.setProps({ errormessage: "Something went wrong." })
55+
await localVue.nextTick()
5456
expect(wrapper.find(".lux-error").exists()).toBe(true)
5557
expect(wrapper.find(".lux-error").attributes().role).toBe("alert")
5658
})

test/unit/specs/components/loader.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ describe("Loader.vue", () => {
1313
})
1414
})
1515

16-
it("should be full screen when fullscreen prop is true", () => {
16+
it("should be full screen when fullscreen prop is true", async () => {
1717
const overlay = wrapper.find(".lux-overlay")
1818
expect(overlay.classes()).not.toContain("lux-fullscreen")
1919
wrapper.setProps({ fullscreen: true })
20+
await localVue.nextTick()
2021
const fs_overlay = wrapper.find(".lux-overlay")
2122
expect(fs_overlay.classes()).toContain("lux-fullscreen")
2223
})

test/unit/specs/components/luxDatePicker.spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ import LuxDatePicker from "@/elements/LuxDatePicker.vue"
44
// create an extended `Vue` constructor
55
const localVue = createLocalVue()
66

7+
const transitionStub = () => ({
8+
render: function(h) {
9+
return this.$options._renderChildren
10+
},
11+
})
12+
713
describe("LuxDatePicker.vue", () => {
814
let wrapper
915

1016
beforeEach(() => {
1117
wrapper = mount(LuxDatePicker, {
1218
localVue,
13-
stubs: ["wrapper", "input-text"],
19+
stubs: { wrapper: true, "input-text": true, transition: transitionStub() },
1420
propsData: {
1521
id: "startDate",
1622
label: "Start Date",

test/unit/specs/components/luxSelect2.spec.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ describe("LuxSelect2.vue", () => {
2323
})
2424
})
2525

26-
it("should accept an optional label", () => {
26+
it("should accept an optional label", async () => {
2727
expect(wrapper.find("label").exists()).toBe(false)
2828
wrapper.setProps({ inputLabel: "Multiple choice:" })
29+
await localVue.nextTick()
2930
expect(wrapper.find("label").exists()).toBe(true)
3031
expect(wrapper.find("label").text()).toBe("Multiple choice:")
3132
})
3233

33-
it("should connect the label to the field using the id", () => {
34+
it("should connect the label to the field using the id", async () => {
3435
wrapper.setProps({ inputLabel: "Multiple choice:" })
36+
await localVue.nextTick()
3537
expect(wrapper.find("label").attributes("for")).toBe("test_id")
3638
expect(wrapper.find("input").attributes("id")).toBe("test_id")
3739
})
@@ -55,11 +57,12 @@ describe("LuxSelect2.vue", () => {
5557
expect(selected_hash.text().includes('code": "js"')).toBe(true)
5658
})
5759

58-
it("should have an optional placeholder with a default", () => {
60+
it("should have an optional placeholder with a default", async () => {
5961
var placeholder = wrapper.find("input").attributes("placeholder")
6062

6163
expect(placeholder).toBe("Search or add a tag")
6264
wrapper.setProps({ placeholder: "Search or add an accessibility need" })
65+
await localVue.nextTick()
6366
var placeholder = wrapper.find("input").attributes("placeholder")
6467
expect(placeholder).toBe("Search or add an accessibility need")
6568
})

test/unit/specs/components/menuBar.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ describe("MenuBar.vue", () => {
2525
})
2626
})
2727

28-
it("should be a nav element if the type prop value is 'links'", () => {
28+
it("should be a nav element if the type prop value is 'links'", async () => {
2929
expect(wrapper.find("nav").exists()).toBe(true)
3030
expect(wrapper.find("div").exists()).toBe(false)
3131
wrapper.setProps({ type: "buttons" })
32+
await localVue.nextTick()
3233
expect(wrapper.find("nav").exists()).toBe(false)
3334
expect(wrapper.find("div").exists()).toBe(true)
3435
})
@@ -40,8 +41,9 @@ describe("MenuBar.vue", () => {
4041
expect(Object.prototype.hasOwnProperty.call(emitted1, "menu-item-clicked")).toBe(true)
4142
})
4243

43-
it("should emit the correct event when menu-item is clicked", () => {
44+
it("should emit the correct event when menu-item is clicked", async () => {
4445
wrapper.setProps({ type: "buttons" })
46+
await localVue.nextTick()
4547
const menuItem = wrapper.find(".lux-menu-item")
4648
menuItem.trigger("click")
4749
const emitted2 = wrapper.emitted()

test/unit/specs/components/tag.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ describe("Tag.vue", () => {
2020
})
2121
})
2222

23-
it("should render the correct type", () => {
23+
it("should render the correct type", async () => {
2424
const tag = wrapper.find(".lux-tag.tag")
2525
expect(tag.is("ul")).toBe(true)
2626
wrapper.setProps({ type: "filter" })
27+
await localVue.nextTick()
2728
const filter = wrapper.find(".lux-tag.filter")
2829
expect(filter.is("ul")).toBe(true)
2930
})

0 commit comments

Comments
 (0)