Skip to content

Instantly share code, notes, and snippets.

@dmattia
Created June 21, 2019 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmattia/5b99dc2584ec8241f84b30b5476b6ff3 to your computer and use it in GitHub Desktop.
Save dmattia/5b99dc2584ec8241f84b30b5476b6ff3 to your computer and use it in GitHub Desktop.
import { mount } from "@vue/test-utils";
const parentComponent = {
provide() {
return {
val: 'from parent'
};
},
template: `
<div>
<slot></slot>
</div>
`
};
const child = {
inject: ["val"],
template: `
<div>{{ val }}</div>
`
};
describe("Bug with providing data", () => {
it("can inject values into a child", () => {
const wrapper = mount(child, {
provide: {
val: "from mount options"
}
});
expect(wrapper.text()).toMatch("from mount options");
});
it("can inject values from a parent", () => {
const template = "<parentComponent><child></child></parentComponent>";
const components = { parentComponent, child };
const wrapper = mount({ template, components });
expect(wrapper.text()).toMatch("from parent");
});
it("fails to inject using parentComponent", () => {
const wrapper = mount(child, { parentComponent });
expect(wrapper.text()).toMatch("from parent");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment