Last active
July 15, 2018 20:45
-
-
Save andrewdelprete/32bc35c31d696e272739bf3e75862aa3 to your computer and use it in GitHub Desktop.
Integration test a Vue component with vue-testing-library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { render, Simulate } from "vue-testing-library"; | |
import Counter from "@/components/Counter.vue"; | |
describe("Counter.vue", () => { | |
it("increments by 1 on click", () => { | |
const { getByTestId, getByText } = render(Counter); | |
Simulate.click(getByText("Increments")); | |
expect(getByTestId("count").textContent).toBe("1"); | |
}); | |
it("decrements by 1 on click", () => { | |
const { getByTestId, getByText } = render(Counter); | |
Simulate.click(getByText("Decrements")); | |
expect(getByTestId("count").textContent).toBe("-1"); | |
}); | |
it("increments by multiplier", () => { | |
const { getByTestId, getByText } = render(Counter, { props: { multiplier: 4 } }); | |
Simulate.click(getByText("Increments")); | |
expect(getByTestId("count").textContent).toBe("4"); | |
}); | |
it("decrements by multiplier", () => { | |
const { getByTestId, getByText } = render(Counter, { props: { multiplier: 4 } }); | |
Simulate.click(getByText("Decrements")); | |
expect(getByTestId("count").textContent).toBe("-4"); | |
}); | |
it("resets to 0", () => { | |
const { getByTestId, getByText } = render(Counter); | |
Simulate.click(getByText("Reset")); | |
expect(getByTestId("count").textContent).toBe("0"); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
moduleFileExtensions: ["js", "jsx", "json", "vue"], | |
transform: { | |
"^.+\\.vue$": "vue-jest", | |
".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub", | |
"^.+\\.jsx?$": "babel-jest" | |
}, | |
moduleNameMapper: { | |
"^@/(.*)$": "<rootDir>/src/$1" | |
}, | |
snapshotSerializers: ["jest-serializer-vue"], | |
testMatch: [ | |
"<rootDir>/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx))", | |
"<rootDir>/tests/integration/**/*.spec.(js|jsx|ts|tsx)" | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment