File tree Expand file tree Collapse file tree 2 files changed +87
-0
lines changed
Expand file tree Collapse file tree 2 files changed +87
-0
lines changed Original file line number Diff line number Diff line change 1+ import consumer from "../Consumer" ;
2+ import { mount } from "@vue/test-utils" ;
3+
4+ const registerComponent = context => ( {
5+ components : {
6+ Consumer : consumer ( context )
7+ }
8+ } ) ;
9+
10+ const ConsumerComponent = context => ( {
11+ template : `
12+ <Consumer>
13+ <span slot-scope="contextValue">
14+ {{ contextValue }}
15+ </span>
16+ </Consumer>
17+ ` ,
18+ ...registerComponent ( context )
19+ } ) ;
20+
21+ const MalformedConsumerComponent = context => ( {
22+ template : `
23+ <Consumer>
24+ <span>
25+ test
26+ </span>
27+ </Consumer>
28+ ` ,
29+ ...registerComponent ( context )
30+ } ) ;
31+
32+ describe ( "Consumer" , ( ) => {
33+ it ( "should return the given context as data" , ( ) => {
34+ const s = Symbol ( ) ;
35+ expect ( consumer ( s ) . data ( ) . context ) . toBe ( s ) ;
36+ } ) ;
37+
38+ it ( "should render the context's value" , ( ) => {
39+ const Consumer = ConsumerComponent ( { value : "test-context" } ) ;
40+ const wrapper = mount ( Consumer ) ;
41+ expect ( wrapper . html ( ) ) . toContain ( "test-context" ) ;
42+ } ) ;
43+
44+ it ( "should not fail to render if consumer is missing slot-scope" , ( ) => {
45+ const Consumer = MalformedConsumerComponent ( { value : "test-context" } ) ;
46+ const wrapper = mount ( Consumer ) ;
47+ expect ( wrapper . html ( ) ) . toContain ( "test" ) ;
48+ } ) ;
49+ } ) ;
Original file line number Diff line number Diff line change 1+ import provider from "../Provider" ;
2+ import { mount } from "@vue/test-utils" ;
3+
4+ describe ( "Provider" , ( ) => {
5+ it ( "should have a prop with the given default value" , ( ) => {
6+ const defaultValue = "TEST" ;
7+ const Provider = provider ( { } , defaultValue ) ;
8+ const wrapper = mount ( Provider , {
9+ slots : {
10+ default : "<span>Test</span>"
11+ }
12+ } ) ;
13+ expect ( wrapper . props ( ) . value ) . toBe ( defaultValue ) ;
14+ } ) ;
15+
16+ it ( "should not overwrite context if no prop provided" , ( ) => {
17+ let context = { value : "test" } ;
18+ const Provider = provider ( context ) ;
19+ const wrapper = mount ( Provider , {
20+ slots : {
21+ default : "<span>Test</span>"
22+ }
23+ } ) ;
24+ expect ( context . value ) . toBeDefined ( ) ;
25+ } ) ;
26+
27+ it ( "should update context when props change" , ( ) => {
28+ let context = { value : "test" } ;
29+ const Provider = provider ( context ) ;
30+ const wrapper = mount ( Provider , {
31+ slots : {
32+ default : "<span>Test</span>"
33+ }
34+ } ) ;
35+ wrapper . setProps ( { value : "123" } ) ;
36+ expect ( context . value ) . toBe ( "123" ) ;
37+ } ) ;
38+ } ) ;
You can’t perform that action at this time.
0 commit comments