Created
June 21, 2019 00:19
-
-
Save dmattia/5b99dc2584ec8241f84b30b5476b6ff3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { 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