Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Initiate snapshot testing for StarsRating comp #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function isBabelLoader(caller) {
return caller && caller.name === "babel-loader";
}

module.exports = function(api) {
if (api.env("test") && !api.caller(isBabelLoader)) {
return {
presets: [
[
"@babel/preset-env",
{
targets: {
node: "current"
}
}
]
]
};
}
return {};
};
2 changes: 1 addition & 1 deletion components/ui/StarsRating.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ export default {
</script>

<style>
</style>
</style>
17 changes: 17 additions & 0 deletions components/ui/__tests__/StarsRating.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createLocalVue, mount } from "@vue/test-utils";
import StarsRating from "@/components/ui/StarsRating";

const factory = () => {
return mount(StarsRating, {
propsData: {
stars: 4
}
})
}

describe('StarsRating', () => {
const wrapper = factory()
test("renders properly", () => {
expect(wrapper.html()).toMatchSnapshot();
});
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`StarsRating renders properly 1`] = `<span><i class="fas fa-star fa-sm fa-fw text-warning"></i><i class="fas fa-star fa-sm fa-fw text-warning"></i><i class="fas fa-star fa-sm fa-fw text-warning"></i><i class="fas fa-star fa-sm fa-fw text-warning"></i><i class="fas fa-star fa-sm fa-fw text-gray-400"></i></span>`;
22 changes: 22 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
// tell Jest to handle `*.vue` files
moduleFileExtensions: ["js", "json", "vue"],
watchman: false,
moduleNameMapper: {
"^~/(.*)$": "<rootDir>/$1",
"^~~/(.*)$": "<rootDir>/$1",
"^@/(.*)$": "<rootDir>/$1"
},
transform: {
// process js with `babel-jest`
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
// process `*.vue` files with `vue-jest`
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
},
snapshotSerializers: ["<rootDir>/node_modules/jest-serializer-vue"],
collectCoverage: true,
collectCoverageFrom: [
"<rootDir>/components/**/*.vue",
"<rootDir>/pages/*.vue"
]
};
Loading