Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyFeliz committed Dec 2, 2019
1 parent a74316d commit 5a25da5
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions tests/unit/email-dropdown.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Vue from "vue"
import { expect } from "chai";
import { shallowMount } from "@vue/test-utils";
import EmailDropdown from "@/components/EmailDropdown.vue";
Expand Down Expand Up @@ -68,7 +69,7 @@ describe("EmailDropdown.vue", () => {
expect(wrapper.vm.optionIsSelected).to.be.true;
});

it("filter the suggestion list when type in the input", () => {
it("filter the suggestion list when type in the input", async () => {
propsData.initialValue = "hello@g";
propsData.domains = ["gmail.com", "google.com"];

Expand All @@ -78,35 +79,42 @@ describe("EmailDropdown.vue", () => {

expect(wrapper.findAll(".email-dropdown-item")).to.have.length(2);
wrapper.find("input").setValue("hello@gma");
await Vue.nextTick();
expect(wrapper.findAll(".email-dropdown-item")).to.have.length(1);
expect(wrapper.find(".email-dropdown-item").text()).to.be.equal("hello@gmail.com");
});

it("emits 'input' on email change", () => {
propsData.domains = ["gmail.com", "google.com"];

const wrapper = shallowMount(EmailDropdown, {
propsData
});

wrapper.find("input").setValue("hello@gmail");
expect(wrapper.emitted().input[0]).to.have.length(1);
expect(wrapper.emitted().input[0][0]).to.be.equal("hello@gmail");
wrapper.find("input").setValue("hello@gmail.");
expect(wrapper.emitted().input[1]).to.have.length(1);
expect(wrapper.emitted().input[1][0]).to.be.equal("hello@gmail.");
});

it("hides suggestion list if remove '@' from the email", () => {
it("hides suggestion list if remove '@' from the email", async () => {
const wrapper = shallowMount(EmailDropdown, {
propsData
});

expect(wrapper.findAll(".email-dropdown-item")).to.have.length(2);
wrapper.find("input").setValue("hello");
await Vue.nextTick();
expect(wrapper.find(".email-dropdown-list").exists()).to.be.false;
});

describe("events", () => {
it("emits 'input' on email change", async () => {
propsData.domains = ["gmail.com", "google.com"];

const wrapper = shallowMount(EmailDropdown, {
propsData
});

wrapper.find("input").setValue("hello@gmail");
await Vue.nextTick();
expect(wrapper.emitted().input[0]).to.have.length(1);
expect(wrapper.emitted().input[0][0]).to.be.equal("hello@gmail");
wrapper.find("input").setValue("hello@gmail.");
await Vue.nextTick();
expect(wrapper.emitted().input[1]).to.have.length(1);
expect(wrapper.emitted().input[1][0]).to.be.equal("hello@gmail.");
});
})

describe("computed", () => {
describe("includesAt", () => {
it("returns 'true' if email includes '@'", () => {
Expand Down

0 comments on commit 5a25da5

Please sign in to comment.