@@ -10,12 +10,9 @@ import {
1010 onWillUpdateProps ,
1111 useComponent ,
1212 useEffect ,
13- useEnv ,
1413 useListener ,
1514 useRef ,
1615 proxy ,
17- useChildSubEnv ,
18- useSubEnv ,
1916 xml ,
2017 OwlError ,
2118 props ,
@@ -177,115 +174,6 @@ describe("hooks", () => {
177174 } ) ;
178175 } ) ;
179176
180- test ( "can use useEnv" , async ( ) => {
181- expect . assertions ( 3 ) ;
182- class Test extends Component {
183- static template = xml `<div><t t-esc="env.val"/></div>` ;
184- setup ( ) {
185- expect ( useEnv ( ) ) . toBe ( this . env ) ;
186- }
187- }
188- const env = { val : 1 } ;
189- await mount ( Test , fixture , { env } ) ;
190- expect ( fixture . innerHTML ) . toBe ( "<div>1</div>" ) ;
191- } ) ;
192-
193- test ( "useSubEnv modifies user env" , async ( ) => {
194- class Test extends Component {
195- static template = xml `<div><t t-esc="env.val"/></div>` ;
196- setup ( ) {
197- useSubEnv ( { val2 : 1 } ) ;
198- }
199- }
200- const env = { val : 3 } ;
201- const component = await mount ( Test , fixture , { env } ) ;
202- expect ( fixture . innerHTML ) . toBe ( "<div>3</div>" ) ;
203- expect ( component . env ) . toHaveProperty ( "val2" ) ;
204- expect ( component . env ) . toHaveProperty ( "val" ) ;
205- } ) ;
206-
207- test ( "useChildSubEnv does not pollute user env" , async ( ) => {
208- class Test extends Component {
209- static template = xml `<div><t t-esc="env.val"/></div>` ;
210- setup ( ) {
211- useChildSubEnv ( { val2 : 1 } ) ;
212- }
213- }
214- const env = { val : 3 } ;
215- const component = await mount ( Test , fixture , { env } ) ;
216- expect ( fixture . innerHTML ) . toBe ( "<div>3</div>" ) ;
217- expect ( component . env ) . not . toHaveProperty ( "val2" ) ;
218- expect ( component . env ) . toHaveProperty ( "val" ) ;
219- } ) ;
220-
221- test ( "useSubEnv supports arbitrary descriptor" , async ( ) => {
222- let someVal = "maggot" ;
223- let someVal2 = "brain" ;
224-
225- class Child extends Component {
226- static template = xml `<div><t t-esc="env.someVal" /> <t t-esc="env.someVal2" /></div>` ;
227- }
228-
229- class Test extends Component {
230- static template = xml `<Child />` ;
231- static components = { Child } ;
232- setup ( ) {
233- useSubEnv ( {
234- get someVal2 ( ) {
235- return someVal2 ;
236- } ,
237- } ) ;
238- }
239- }
240-
241- const env = {
242- get someVal ( ) {
243- return someVal ;
244- } ,
245- } ;
246- const component = await mount ( Test , fixture , { env } ) ;
247- expect ( fixture . innerHTML ) . toBe ( "<div>maggot brain</div>" ) ;
248- someVal = "brain" ;
249- someVal2 = "maggot" ;
250- component . render ( true ) ;
251- await nextTick ( ) ;
252- expect ( fixture . innerHTML ) . toBe ( "<div>brain maggot</div>" ) ;
253- } ) ;
254-
255- test ( "useChildSubEnv supports arbitrary descriptor" , async ( ) => {
256- let someVal = "maggot" ;
257- let someVal2 = "brain" ;
258-
259- class Child extends Component {
260- static template = xml `<div><t t-esc="env.someVal" /> <t t-esc="env.someVal2" /></div>` ;
261- }
262-
263- class Test extends Component {
264- static template = xml `<Child />` ;
265- static components = { Child } ;
266- setup ( ) {
267- useChildSubEnv ( {
268- get someVal2 ( ) {
269- return someVal2 ;
270- } ,
271- } ) ;
272- }
273- }
274- someVal = "maggot" ;
275- const env = {
276- get someVal ( ) {
277- return someVal ;
278- } ,
279- } ;
280- const component = await mount ( Test , fixture , { env } ) ;
281- expect ( fixture . innerHTML ) . toBe ( "<div>maggot brain</div>" ) ;
282- someVal = "brain" ;
283- someVal2 = "maggot" ;
284- component . render ( true ) ;
285- await nextTick ( ) ;
286- expect ( fixture . innerHTML ) . toBe ( "<div>brain maggot</div>" ) ;
287- } ) ;
288-
289177 test ( "can use useComponent" , async ( ) => {
290178 expect . assertions ( 2 ) ;
291179 class Test extends Component {
@@ -297,58 +185,6 @@ describe("hooks", () => {
297185 await mount ( Test , fixture ) ;
298186 } ) ;
299187
300- test ( "parent and child env (with useSubEnv)" , async ( ) => {
301- class Child extends Component {
302- static template = xml `<div><t t-esc="env.val"/></div>` ;
303- }
304-
305- class Parent extends Component {
306- static template = xml `<t t-esc="env.val"/><Child/>` ;
307- static components = { Child } ;
308- setup ( ) {
309- useSubEnv ( { val : 5 } ) ;
310- }
311- }
312- const env = { val : 3 } ;
313- await mount ( Parent , fixture , { env } ) ;
314- expect ( fixture . innerHTML ) . toBe ( "5<div>5</div>" ) ;
315- } ) ;
316-
317- test ( "parent and child env (with useChildSubEnv)" , async ( ) => {
318- class Child extends Component {
319- static template = xml `<div><t t-esc="env.val"/></div>` ;
320- }
321-
322- class Parent extends Component {
323- static template = xml `<t t-esc="env.val"/><Child/>` ;
324- static components = { Child } ;
325- setup ( ) {
326- useChildSubEnv ( { val : 5 } ) ;
327- }
328- }
329- const env = { val : 3 } ;
330- await mount ( Parent , fixture , { env } ) ;
331- expect ( fixture . innerHTML ) . toBe ( "3<div>5</div>" ) ;
332- } ) ;
333-
334- test ( "parent and child env (with useChildSubEnv then useSubEnv)" , async ( ) => {
335- class Child extends Component {
336- static template = xml `<div t-if="env.hasParent"><t t-esc="env.val"/></div>` ;
337- }
338-
339- class Parent extends Component {
340- static template = xml `<t t-esc="env.val"/><Child/>` ;
341- static components = { Child } ;
342- setup ( ) {
343- useChildSubEnv ( { hasParent : true } ) ;
344- useSubEnv ( { val : 5 } ) ;
345- }
346- }
347- const env = { val : 3 } ;
348- await mount ( Parent , fixture , { env } ) ;
349- expect ( fixture . innerHTML ) . toBe ( "5<div>5</div>" ) ;
350- } ) ;
351-
352188 test ( "can use onWillStart, onWillUpdateProps" , async ( ) => {
353189 const steps : string [ ] = [ ] ;
354190 async function slow ( ) : Promise < string > {
0 commit comments