11// tslint:disable max-classes-per-file jsx-no-lambda
22import { mount } from 'enzyme'
33import React from 'react'
4+ import { createConsumer } from '..'
45import { createApp } from '../../core/createApp/createApp'
56import { createEvent } from '../../core/createEvent/createEvent'
67import { createReducer } from '../../core/createReducer/createReducer'
78import { uniqueId } from '../../helpers/uniqueId/uniqueId'
89import { createConsume } from './createConsume'
910
10- describe ( 'createContext ' , ( ) => {
11+ describe ( 'createConsumer ' , ( ) => {
1112 const initialState = {
1213 test : 0
1314 }
@@ -31,11 +32,13 @@ describe('createContext', () => {
3132 ]
3233 } )
3334
35+ const getConsumer = ( ) => createConsumer ( getApp ( ) )
36+
3437 it ( 'should pass state to wrapped component' , ( done ) => {
3538 expect . assertions ( 2 )
3639
37- const app = getApp ( )
38- const consume = createConsume ( app )
40+ const Consumer = getConsumer ( )
41+ const consume = createConsume ( Consumer )
3942
4043 const Dummy = consume ( ) (
4144 class extends React . Component < any > {
@@ -58,8 +61,8 @@ describe('createContext', () => {
5861 it ( 'should use mapState' , ( done ) => {
5962 expect . assertions ( 4 )
6063
61- const app = getApp ( )
62- const consume = createConsume ( app )
64+ const Consumer = getConsumer ( )
65+ const consume = createConsume ( Consumer )
6366
6467 const Dummy = consume ( ( state ) => ( {
6568 test : state . r1 . test + 5 ,
@@ -91,8 +94,9 @@ describe('createContext', () => {
9194 it ( 'should use mapApi' , ( done ) => {
9295 expect . assertions ( 2 )
9396
94- const app = getApp ( )
95- const consume = createConsume ( app )
97+ const Consumer = getConsumer ( )
98+ const app = Consumer . app
99+ const consume = createConsume ( Consumer )
96100
97101 const Dummy = consume ( undefined , ( api ) => ( {
98102 e2 : api . e1
@@ -116,8 +120,9 @@ describe('createContext', () => {
116120 it ( 'should accept props at mapApi' , ( done ) => {
117121 expect . assertions ( 3 )
118122
119- const app = getApp ( )
120- const consume = createConsume ( app )
123+ const Consumer = getConsumer ( )
124+ const app = Consumer . app
125+ const consume = createConsume ( Consumer )
121126
122127 const Dummy = consume ( undefined , ( api , props ) => ( {
123128 e1 : {
@@ -147,8 +152,8 @@ describe('createContext', () => {
147152 it ( 'should accepts props in mapState' , ( done ) => {
148153 expect . assertions ( 4 )
149154
150- const app = getApp ( )
151- const consume = createConsume ( app )
155+ const Consumer = getConsumer ( )
156+ const consume = createConsume ( Consumer )
152157
153158 const Dummy = consume ( ( state , props ) => ( {
154159 test : state . r1 . test + 5 ,
@@ -178,8 +183,8 @@ describe('createContext', () => {
178183 it ( 'should accept mergeprops' , ( done ) => {
179184 expect . assertions ( 4 )
180185
181- const app = getApp ( )
182- const consume = createConsume ( app )
186+ const Consumer = getConsumer ( )
187+ const consume = createConsume ( Consumer )
183188
184189 const Dummy = consume (
185190 ( state , props ) => ( {
@@ -222,8 +227,8 @@ describe('createContext', () => {
222227 it ( 'should work with stateless components' , ( done ) => {
223228 expect . assertions ( 2 )
224229
225- const app = getApp ( )
226- const consume = createConsume ( app )
230+ const Consumer = getConsumer ( )
231+ const consume = createConsume ( Consumer )
227232
228233 const Dummy = consume ( ) ( ( props : any ) => {
229234 expect ( typeof props . e1 ) . toBe ( 'function' )
0 commit comments