⌈⌋ ⎇ branch:  Bitrhythm


Hex Artifact Content

Artifact 6db6d719ab927a0d09f110ef0bb648a99a9d258807cf1d25e5b3cc36b016e362:


0000: 69 6d 70 6f 72 74 20 7b 0a 20 20 69 6e 6a 65 63  import {.  injec
0010: 74 48 54 4d 4c 2c 0a 20 20 65 78 70 65 63 74 48  tHTML,.  expectH
0020: 54 4d 4c 2c 0a 20 20 24 24 2c 0a 20 20 66 69 72  TML,.  $$,.  fir
0030: 65 45 76 65 6e 74 0a 7d 20 66 72 6f 6d 20 27 2e  eEvent.} from '.
0040: 2e 2f 2e 2e 2f 2e 2e 2f 68 65 6c 70 65 72 73 2f  ./../../helpers/
0050: 69 6e 64 65 78 27 0a 0a 0a 2f 2f 20 69 6e 63 6c  index'...// incl
0060: 75 64 65 20 73 70 65 63 69 61 6c 20 74 61 67 73  ude special tags
0070: 20 74 6f 20 74 65 73 74 20 73 70 65 63 69 66 69   to test specifi
0080: 63 20 66 65 61 74 75 72 65 73 0a 69 6d 70 6f 72  c features.impor
0090: 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f  t '../../../tag/
00a0: 69 66 2d 6d 6f 75 6e 74 2e 74 61 67 27 0a 69 6d  if-mount.tag'.im
00b0: 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74  port '../../../t
00c0: 61 67 2f 6e 65 73 74 65 64 2d 63 68 69 6c 64 2e  ag/nested-child.
00d0: 74 61 67 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f  tag'.import '../
00e0: 2e 2e 2f 2e 2e 2f 74 61 67 2f 69 66 2d 75 6e 6d  ../../tag/if-unm
00f0: 6f 75 6e 74 2e 74 61 67 27 0a 69 6d 70 6f 72 74  ount.tag'.import
0100: 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6e   '../../../tag/n
0110: 61 6d 65 64 2d 75 6e 6d 6f 75 6e 74 2e 74 61 67  amed-unmount.tag
0120: 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f  '.import '../../
0130: 2e 2e 2f 74 61 67 2f 62 75 67 2d 32 32 32 39 2e  ../tag/bug-2229.
0140: 74 61 67 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f  tag'.import '../
0150: 2e 2e 2f 2e 2e 2f 74 61 67 2f 62 75 67 2d 32 36  ../../tag/bug-26
0160: 30 39 2e 74 61 67 27 0a 0a 64 65 73 63 72 69 62  09.tag'..describ
0170: 65 28 27 52 69 6f 74 20 69 66 27 2c 20 66 75 6e  e('Riot if', fun
0180: 63 74 69 6f 6e 28 29 20 7b 0a 20 20 69 74 28 27  ction() {.  it('
0190: 63 68 69 6c 64 20 74 61 67 73 20 61 72 65 20 6f  child tags are o
01a0: 6e 6c 79 20 72 65 6e 64 65 72 65 64 20 77 68 65  nly rendered whe
01b0: 6e 20 69 66 2d 63 6f 6e 64 69 74 69 6f 6e 20 69  n if-condition i
01c0: 73 20 74 72 75 74 68 79 27 2c 20 66 75 6e 63 74  s truthy', funct
01d0: 69 6f 6e 28 29 20 7b 0a 0a 20 20 20 20 69 6e 6a  ion() {..    inj
01e0: 65 63 74 48 54 4d 4c 28 27 3c 69 66 2d 6d 6f 75  ectHTML('<if-mou
01f0: 6e 74 3e 3c 2f 69 66 2d 6d 6f 75 6e 74 3e 27 29  nt></if-mount>')
0200: 0a 0a 20 20 20 20 76 61 72 20 74 61 67 20 3d 20  ..    var tag = 
0210: 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 69 66 2d 6d  riot.mount('if-m
0220: 6f 75 6e 74 27 29 5b 30 5d 0a 0a 20 20 20 20 76  ount')[0]..    v
0230: 61 72 20 65 78 70 65 63 74 4c 32 20 3d 20 66 75  ar expectL2 = fu
0240: 6e 63 74 69 6f 6e 28 62 61 73 65 2c 20 65 78 69  nction(base, exi
0250: 73 74 29 20 7b 0a 20 20 20 20 20 20 76 61 72 20  st) {.      var 
0260: 65 78 20 3d 20 65 78 70 65 63 74 28 62 61 73 65  ex = expect(base
0270: 2e 74 61 67 73 5b 27 69 66 2d 6c 65 76 65 6c 32  .tags['if-level2
0280: 27 5d 29 0a 20 20 20 20 20 20 65 78 69 73 74 20  ']).      exist 
0290: 3f 20 65 78 2e 74 6f 2e 6e 6f 74 2e 62 65 2e 75  ? ex.to.not.be.u
02a0: 6e 64 65 66 69 6e 65 64 20 3a 20 65 78 2e 74 6f  ndefined : ex.to
02b0: 2e 62 65 2e 75 6e 64 65 66 69 6e 65 64 0a 20 20  .be.undefined.  
02c0: 20 20 20 20 65 78 70 65 63 74 28 24 24 28 27 69      expect($$('i
02d0: 66 2d 6c 65 76 65 6c 32 27 2c 20 62 61 73 65 2e  f-level2', base.
02e0: 72 6f 6f 74 29 2e 6c 65 6e 67 74 68 29 2e 74 6f  root).length).to
02f0: 2e 62 65 2e 65 71 75 61 6c 28 65 78 69 73 74 20  .be.equal(exist 
0300: 3f 20 31 20 3a 20 30 29 0a 20 20 20 20 7d 0a 0a  ? 1 : 0).    }..
0310: 20 20 20 20 76 61 72 20 65 78 70 65 63 74 43 6f      var expectCo
0320: 6e 64 20 3d 20 66 75 6e 63 74 69 6f 6e 28 62 61  nd = function(ba
0330: 73 65 2c 20 65 78 69 73 74 29 20 7b 0a 20 20 20  se, exist) {.   
0340: 20 20 20 76 61 72 20 65 78 20 3d 20 65 78 70 65     var ex = expe
0350: 63 74 28 62 61 73 65 2e 74 61 67 73 5b 27 69 66  ct(base.tags['if
0360: 2d 6c 65 76 65 6c 32 27 5d 2e 74 61 67 73 5b 27  -level2'].tags['
0370: 63 6f 6e 64 69 74 69 6f 6e 61 6c 2d 74 61 67 27  conditional-tag'
0380: 5d 29 0a 20 20 20 20 20 20 65 78 69 73 74 20 3f  ]).      exist ?
0390: 20 65 78 2e 74 6f 2e 6e 6f 74 2e 62 65 2e 75 6e   ex.to.not.be.un
03a0: 64 65 66 69 6e 65 64 20 3a 20 65 78 2e 74 6f 2e  defined : ex.to.
03b0: 62 65 2e 75 6e 64 65 66 69 6e 65 64 0a 20 20 20  be.undefined.   
03c0: 20 20 20 65 78 70 65 63 74 28 24 24 28 27 63 6f     expect($$('co
03d0: 6e 64 69 74 69 6f 6e 61 6c 2d 74 61 67 27 2c 20  nditional-tag', 
03e0: 62 61 73 65 2e 72 6f 6f 74 29 2e 6c 65 6e 67 74  base.root).lengt
03f0: 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 65  h).to.be.equal(e
0400: 78 69 73 74 20 3f 20 31 20 3a 20 30 29 0a 20 20  xist ? 1 : 0).  
0410: 20 20 7d 0a 0a 20 20 20 20 65 78 70 65 63 74 4c    }..    expectL
0420: 32 28 74 61 67 2e 72 65 66 73 2e 66 66 2c 20 66  2(tag.refs.ff, f
0430: 61 6c 73 65 29 0a 20 20 20 20 65 78 70 65 63 74  alse).    expect
0440: 4c 32 28 74 61 67 2e 72 65 66 73 2e 66 74 2c 20  L2(tag.refs.ft, 
0450: 66 61 6c 73 65 29 0a 0a 20 20 20 20 65 78 70 65  false)..    expe
0460: 63 74 4c 32 28 74 61 67 2e 72 65 66 73 2e 74 66  ctL2(tag.refs.tf
0470: 2c 20 74 72 75 65 29 0a 20 20 20 20 65 78 70 65  , true).    expe
0480: 63 74 43 6f 6e 64 28 74 61 67 2e 72 65 66 73 2e  ctCond(tag.refs.
0490: 74 66 2c 20 66 61 6c 73 65 29 0a 0a 20 20 20 20  tf, false)..    
04a0: 65 78 70 65 63 74 4c 32 28 74 61 67 2e 72 65 66  expectL2(tag.ref
04b0: 73 2e 74 74 2c 20 74 72 75 65 29 0a 20 20 20 20  s.tt, true).    
04c0: 65 78 70 65 63 74 43 6f 6e 64 28 74 61 67 2e 72  expectCond(tag.r
04d0: 65 66 73 2e 74 74 2c 20 74 72 75 65 29 0a 0a 20  efs.tt, true).. 
04e0: 20 20 20 74 61 67 2e 72 65 66 73 2e 74 66 2e 74     tag.refs.tf.t
04f0: 61 67 73 5b 27 69 66 2d 6c 65 76 65 6c 32 27 5d  ags['if-level2']
0500: 2e 74 6f 67 67 6c 65 43 6f 6e 64 69 74 69 6f 6e  .toggleCondition
0510: 28 29 0a 20 20 20 20 65 78 70 65 63 74 43 6f 6e  ().    expectCon
0520: 64 28 74 61 67 2e 72 65 66 73 2e 74 66 2c 20 74  d(tag.refs.tf, t
0530: 72 75 65 29 0a 0a 20 20 20 20 74 61 67 2e 72 65  rue)..    tag.re
0540: 66 73 2e 66 74 2e 74 6f 67 67 6c 65 43 6f 6e 64  fs.ft.toggleCond
0550: 69 74 69 6f 6e 28 29 0a 20 20 20 20 65 78 70 65  ition().    expe
0560: 63 74 4c 32 28 74 61 67 2e 72 65 66 73 2e 66 74  ctL2(tag.refs.ft
0570: 2c 20 74 72 75 65 29 0a 20 20 20 20 65 78 70 65  , true).    expe
0580: 63 74 43 6f 6e 64 28 74 61 67 2e 72 65 66 73 2e  ctCond(tag.refs.
0590: 66 74 2c 20 74 72 75 65 29 0a 0a 20 20 20 20 74  ft, true)..    t
05a0: 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d  ag.unmount().  }
05b0: 29 0a 0a 20 20 69 74 28 27 74 61 67 73 20 75 6e  )..  it('tags un
05c0: 64 65 72 20 61 20 66 61 6c 73 65 20 69 66 20 73  der a false if s
05d0: 74 61 74 65 6d 65 6e 74 20 61 72 65 20 75 6e 6d  tatement are unm
05e0: 6f 75 6e 74 65 64 27 2c 20 66 75 6e 63 74 69 6f  ounted', functio
05f0: 6e 28 29 20 7b 0a 0a 20 20 20 20 69 6e 6a 65 63  n() {..    injec
0600: 74 48 54 4d 4c 28 27 3c 69 66 2d 75 6e 6d 6f 75  tHTML('<if-unmou
0610: 6e 74 3e 3c 2f 69 66 2d 75 6e 6d 6f 75 6e 74 3e  nt></if-unmount>
0620: 27 29 0a 0a 20 20 20 20 76 61 72 20 63 62 20 3d  ')..    var cb =
0630: 20 73 69 6e 6f 6e 2e 73 70 79 28 29 0a 20 20 20   sinon.spy().   
0640: 20 76 61 72 20 74 61 67 20 3d 20 72 69 6f 74 2e   var tag = riot.
0650: 6d 6f 75 6e 74 28 27 69 66 2d 75 6e 6d 6f 75 6e  mount('if-unmoun
0660: 74 27 2c 20 7b 63 62 3a 20 63 62 7d 29 5b 30 5d  t', {cb: cb})[0]
0670: 0a 0a 20 20 20 20 2f 2f 20 63 68 65 63 6b 20 74  ..    // check t
0680: 68 61 74 20 6f 75 72 20 63 68 69 6c 64 20 74 61  hat our child ta
0690: 67 73 20 65 78 69 73 74 2c 20 61 6e 64 20 72 65  gs exist, and re
06a0: 63 6f 72 64 20 74 68 65 69 72 20 69 64 73 0a 20  cord their ids. 
06b0: 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 74 61     expect(tag.ta
06c0: 67 73 5b 27 69 66 2d 75 63 68 69 6c 64 27 5d 2e  gs['if-uchild'].
06d0: 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71  length).to.be.eq
06e0: 75 61 6c 28 33 29 0a 20 20 20 20 76 61 72 20 66  ual(3).    var f
06f0: 69 72 73 74 49 64 73 20 3d 20 74 61 67 2e 74 61  irstIds = tag.ta
0700: 67 73 5b 27 69 66 2d 75 63 68 69 6c 64 27 5d 2e  gs['if-uchild'].
0710: 6d 61 70 28 66 75 6e 63 74 69 6f 6e 28 63 29 20  map(function(c) 
0720: 7b 20 72 65 74 75 72 6e 20 63 2e 5f 72 69 6f 74  { return c._riot
0730: 5f 69 64 20 7d 29 0a 0a 20 20 20 20 2f 2f 20 73  _id })..    // s
0740: 65 74 20 69 66 20 63 6f 6e 64 69 74 69 6f 6e 73  et if conditions
0750: 20 74 6f 20 66 61 6c 73 65 0a 20 20 20 20 74 61   to false.    ta
0760: 67 2e 69 74 65 6d 73 5b 30 5d 2e 62 6f 6f 6c 20  g.items[0].bool 
0770: 3d 20 66 61 6c 73 65 0a 20 20 20 20 74 61 67 2e  = false.    tag.
0780: 75 70 64 61 74 65 28 7b 63 6f 6e 64 3a 20 66 61  update({cond: fa
0790: 6c 73 65 7d 29 0a 0a 20 20 20 20 2f 2f 20 65 6e  lse})..    // en
07a0: 73 75 72 65 20 74 68 65 20 74 61 67 73 20 61 72  sure the tags ar
07b0: 65 20 67 6f 6e 65 2c 20 61 6e 64 20 74 68 61 74  e gone, and that
07c0: 20 74 68 65 69 72 20 75 6d 6f 75 6e 74 20 63 61   their umount ca
07d0: 6c 6c 62 61 63 6b 73 20 77 65 72 65 20 74 72 69  llbacks were tri
07e0: 67 67 65 72 65 64 0a 20 20 20 20 65 78 70 65 63  ggered.    expec
07f0: 74 28 74 61 67 2e 74 61 67 73 5b 27 69 66 2d 75  t(tag.tags['if-u
0800: 63 68 69 6c 64 27 5d 29 2e 74 6f 2e 62 65 2e 75  child']).to.be.u
0810: 6e 64 65 66 69 6e 65 64 0a 20 20 20 20 65 78 70  ndefined.    exp
0820: 65 63 74 28 63 62 29 2e 74 6f 2e 68 61 76 65 2e  ect(cb).to.have.
0830: 62 65 65 6e 2e 63 61 6c 6c 65 64 54 68 72 69 63  been.calledThric
0840: 65 0a 0a 20 20 20 20 2f 2f 20 73 65 74 20 63 6f  e..    // set co
0850: 6e 64 69 74 69 6f 6e 73 20 62 61 63 6b 20 74 6f  nditions back to
0860: 20 74 72 75 65 0a 20 20 20 20 74 61 67 2e 69 74   true.    tag.it
0870: 65 6d 73 5b 30 5d 2e 62 6f 6f 6c 20 3d 20 74 72  ems[0].bool = tr
0880: 75 65 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74  ue.    tag.updat
0890: 65 28 7b 63 6f 6e 64 3a 20 74 72 75 65 7d 29 0a  e({cond: true}).
08a0: 0a 20 20 20 20 2f 2f 20 65 6e 73 75 72 65 20 74  .    // ensure t
08b0: 68 65 20 74 61 67 73 20 65 78 69 73 74 2c 20 61  he tags exist, a
08c0: 6e 64 20 67 65 74 20 74 68 65 69 72 20 69 64 73  nd get their ids
08d0: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e  .    expect(tag.
08e0: 74 61 67 73 5b 27 69 66 2d 75 63 68 69 6c 64 27  tags['if-uchild'
08f0: 5d 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e  ].length).to.be.
0900: 65 71 75 61 6c 28 33 29 0a 20 20 20 20 76 61 72  equal(3).    var
0910: 20 73 65 63 6f 6e 64 49 64 73 20 3d 20 74 61 67   secondIds = tag
0920: 2e 74 61 67 73 5b 27 69 66 2d 75 63 68 69 6c 64  .tags['if-uchild
0930: 27 5d 2e 6d 61 70 28 66 75 6e 63 74 69 6f 6e 28  '].map(function(
0940: 63 29 20 7b 20 72 65 74 75 72 6e 20 63 2e 5f 72  c) { return c._r
0950: 69 6f 74 5f 69 64 20 7d 29 0a 0a 20 20 20 20 2f  iot_id })..    /
0960: 2f 20 65 6e 73 75 72 65 20 74 68 61 74 20 61 6c  / ensure that al
0970: 6c 20 6f 66 20 74 68 65 20 6e 65 77 20 74 61 67  l of the new tag
0980: 73 20 61 72 65 20 64 69 66 66 65 72 65 6e 74 20  s are different 
0990: 69 6e 73 74 61 6e 63 65 73 20 66 72 6f 6d 20 74  instances from t
09a0: 68 65 20 66 69 72 73 74 20 74 69 6d 65 0a 20 20  he first time.  
09b0: 20 20 76 61 72 20 69 6e 74 65 72 73 65 63 74 69    var intersecti
09c0: 6f 6e 20 3d 20 73 65 63 6f 6e 64 49 64 73 2e 66  on = secondIds.f
09d0: 69 6c 74 65 72 28 66 75 6e 63 74 69 6f 6e 28 69  ilter(function(i
09e0: 64 32 29 20 7b 0a 20 20 20 20 20 20 72 65 74 75  d2) {.      retu
09f0: 72 6e 20 66 69 72 73 74 49 64 73 2e 69 6e 64 65  rn firstIds.inde
0a00: 78 4f 66 28 69 64 32 29 20 3e 20 2d 31 0a 20 20  xOf(id2) > -1.  
0a10: 20 20 7d 29 0a 20 20 20 20 65 78 70 65 63 74 28    }).    expect(
0a20: 69 6e 74 65 72 73 65 63 74 69 6f 6e 2e 6c 65 6e  intersection.len
0a30: 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  gth).to.be.equal
0a40: 28 30 29 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d  (0)..    tag.unm
0a50: 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69  ount().  })..  i
0a60: 74 28 27 72 65 66 73 20 61 72 65 20 72 65 6d 6f  t('refs are remo
0a70: 76 65 64 20 66 72 6f 6d 20 70 61 72 65 6e 74 20  ved from parent 
0a80: 77 68 65 6e 20 65 6c 65 6d 65 6e 74 20 6c 65 61  when element lea
0a90: 76 65 73 20 44 4f 4d 27 2c 20 66 75 6e 63 74 69  ves DOM', functi
0aa0: 6f 6e 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63  on() {.    injec
0ab0: 74 48 54 4d 4c 28 27 3c 6e 61 6d 65 64 2d 75 6e  tHTML('<named-un
0ac0: 6d 6f 75 6e 74 3e 3c 2f 6e 61 6d 65 64 2d 75 6e  mount></named-un
0ad0: 6d 6f 75 6e 74 3e 27 29 0a 20 20 20 20 76 61 72  mount>').    var
0ae0: 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e   tag = riot.moun
0af0: 74 28 27 6e 61 6d 65 64 2d 75 6e 6d 6f 75 6e 74  t('named-unmount
0b00: 27 29 5b 30 5d 0a 0a 20 20 20 20 65 78 70 65 63  ')[0]..    expec
0b10: 74 28 74 61 67 2e 72 65 66 73 2e 66 69 72 73 74  t(tag.refs.first
0b20: 29 2e 74 6f 2e 62 65 2e 75 6e 64 65 66 69 6e 65  ).to.be.undefine
0b30: 64 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67  d.    expect(tag
0b40: 2e 72 65 66 73 2e 73 65 63 6f 6e 64 29 2e 74 6f  .refs.second).to
0b50: 2e 62 65 2e 75 6e 64 65 66 69 6e 65 64 0a 0a 20  .be.undefined.. 
0b60: 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 7b 63     tag.update({c
0b70: 6f 6e 64 3a 20 74 72 75 65 2c 20 69 74 65 6d 73  ond: true, items
0b80: 3a 20 5b 27 74 68 69 72 64 27 5d 7d 29 0a 0a 20  : ['third']}).. 
0b90: 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 72 65     expect(tag.re
0ba0: 66 73 2e 66 69 72 73 74 29 2e 74 6f 2e 62 65 2e  fs.first).to.be.
0bb0: 6f 6b 0a 20 20 20 20 65 78 70 65 63 74 28 74 61  ok.    expect(ta
0bc0: 67 2e 72 65 66 73 2e 73 65 63 6f 6e 64 29 2e 74  g.refs.second).t
0bd0: 6f 2e 62 65 2e 6f 6b 0a 20 20 20 20 65 78 70 65  o.be.ok.    expe
0be0: 63 74 28 74 61 67 2e 72 65 66 73 2e 74 68 69 72  ct(tag.refs.thir
0bf0: 64 29 2e 74 6f 2e 62 65 2e 6f 6b 0a 0a 20 20 20  d).to.be.ok..   
0c00: 20 74 61 67 2e 75 70 64 61 74 65 28 7b 63 6f 6e   tag.update({con
0c10: 64 3a 20 66 61 6c 73 65 2c 20 69 74 65 6d 73 3a  d: false, items:
0c20: 20 5b 5d 7d 29 0a 0a 20 20 20 20 65 78 70 65 63   []})..    expec
0c30: 74 28 74 61 67 2e 72 65 66 73 2e 66 69 72 73 74  t(tag.refs.first
0c40: 29 2e 74 6f 2e 62 65 2e 75 6e 64 65 66 69 6e 65  ).to.be.undefine
0c50: 64 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67  d.    expect(tag
0c60: 2e 72 65 66 73 2e 73 65 63 6f 6e 64 29 2e 74 6f  .refs.second).to
0c70: 2e 62 65 2e 75 6e 64 65 66 69 6e 65 64 0a 20 20  .be.undefined.  
0c80: 20 20 65 78 70 65 63 74 28 74 61 67 2e 72 65 66    expect(tag.ref
0c90: 73 2e 74 68 69 72 64 29 2e 74 6f 2e 62 65 2e 75  s.third).to.be.u
0ca0: 6e 64 65 66 69 6e 65 64 0a 0a 20 20 20 20 74 61  ndefined..    ta
0cb0: 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29  g.unmount().  })
0cc0: 0a 0a 20 20 69 74 28 27 43 6f 6e 64 69 74 69 6f  ..  it('Conditio
0cd0: 6e 61 6c 20 74 61 67 73 20 73 68 6f 75 6c 64 20  nal tags should 
0ce0: 6e 6f 74 20 69 6e 68 65 72 69 74 20 66 72 6f 6d  not inherit from
0cf0: 20 74 68 65 20 70 61 72 65 6e 74 20 75 6e 6c 65   the parent unle
0d00: 73 73 20 74 68 65 79 20 61 72 65 20 69 6e 20 61  ss they are in a
0d10: 20 6c 6f 6f 70 27 2c 20 66 75 6e 63 74 69 6f 6e   loop', function
0d20: 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48  () {.    injectH
0d30: 54 4d 4c 28 27 3c 6e 65 73 74 65 64 2d 63 68 69  TML('<nested-chi
0d40: 6c 64 3e 3c 2f 6e 65 73 74 65 64 2d 63 68 69 6c  ld></nested-chil
0d50: 64 3e 27 29 0a 20 20 20 20 76 61 72 20 74 61 67  d>').    var tag
0d60: 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6e   = riot.mount('n
0d70: 65 73 74 65 64 2d 63 68 69 6c 64 27 29 5b 30 5d  ested-child')[0]
0d80: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e  .    expect(tag.
0d90: 74 61 67 73 2e 63 68 69 6c 64 5b 30 5d 2e 6e 61  tags.child[0].na
0da0: 6d 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  me).to.be.equal(
0db0: 75 6e 64 65 66 69 6e 65 64 29 0a 0a 20 20 20 20  undefined)..    
0dc0: 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20  tag.unmount().  
0dd0: 7d 29 0a 0a 20 20 69 74 28 27 41 20 63 75 73 74  })..  it('A cust
0de0: 6f 6d 20 74 61 67 20 77 69 74 68 20 61 6e 20 69  om tag with an i
0df0: 66 20 64 69 73 70 61 74 63 68 65 73 20 74 68 65  f dispatches the
0e00: 20 22 6d 6f 75 6e 74 22 2c 20 22 75 70 64 61 74   "mount", "updat
0e10: 65 22 20 61 6e 64 20 22 75 70 64 61 74 65 64 22  e" and "updated"
0e20: 20 70 72 6f 70 65 72 6c 79 27 2c 20 66 75 6e 63   properly', func
0e30: 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 69 6e 6a  tion() {.    inj
0e40: 65 63 74 48 54 4d 4c 28 27 3c 72 69 6f 74 2d 74  ectHTML('<riot-t
0e50: 6d 70 3e 3c 2f 72 69 6f 74 2d 74 6d 70 3e 27 29  mp></riot-tmp>')
0e60: 0a 0a 20 20 20 20 76 61 72 20 73 70 79 20 3d 20  ..    var spy = 
0e70: 73 69 6e 6f 6e 2e 73 70 79 28 29 2c 20 74 61 67  sinon.spy(), tag
0e80: 0a 0a 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27  ..    riot.tag('
0e90: 69 6e 6e 65 72 27 2c 20 27 3c 62 72 3e 27 2c 20  inner', '<br>', 
0ea0: 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20  function() {.   
0eb0: 20 20 20 74 68 69 73 2e 6f 6e 28 27 6d 6f 75 6e     this.on('moun
0ec0: 74 27 2c 20 73 70 79 29 0a 20 20 20 20 20 20 74  t', spy).      t
0ed0: 68 69 73 2e 6f 6e 28 27 75 70 64 61 74 65 27 2c  his.on('update',
0ee0: 20 73 70 79 29 0a 20 20 20 20 20 20 74 68 69 73   spy).      this
0ef0: 2e 6f 6e 28 27 75 70 64 61 74 65 64 27 2c 20 73  .on('updated', s
0f00: 70 79 29 0a 20 20 20 20 7d 29 0a 20 20 20 20 72  py).    }).    r
0f10: 69 6f 74 2e 74 61 67 28 27 72 69 6f 74 2d 74 6d  iot.tag('riot-tm
0f20: 70 27 2c 20 27 3c 69 6e 6e 65 72 20 69 66 3d 22  p', '<inner if="
0f30: 7b 63 6f 6e 64 7d 22 20 2f 3e 27 2c 20 66 75 6e  {cond}" />', fun
0f40: 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 20 20  ction() {.      
0f50: 74 68 69 73 2e 63 6f 6e 64 20 3d 20 66 61 6c 73  this.cond = fals
0f60: 65 0a 20 20 20 20 7d 29 0a 0a 20 20 20 20 74 61  e.    })..    ta
0f70: 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27  g = riot.mount('
0f80: 72 69 6f 74 2d 74 6d 70 27 29 5b 30 5d 0a 20 20  riot-tmp')[0].  
0f90: 20 20 65 78 70 65 63 74 28 73 70 79 29 2e 74 6f    expect(spy).to
0fa0: 2e 6e 6f 74 2e 68 61 76 65 2e 62 65 65 6e 2e 63  .not.have.been.c
0fb0: 61 6c 6c 65 64 0a 0a 20 20 20 20 74 61 67 2e 75  alled..    tag.u
0fc0: 70 64 61 74 65 28 7b 63 6f 6e 64 3a 20 74 72 75  pdate({cond: tru
0fd0: 65 7d 29 0a 20 20 20 20 65 78 70 65 63 74 28 73  e}).    expect(s
0fe0: 70 79 29 2e 74 6f 2e 68 61 76 65 2e 62 65 65 6e  py).to.have.been
0ff0: 2e 63 61 6c 6c 65 64 4f 6e 63 65 20 2f 2f 20 6f  .calledOnce // o
1000: 6e 6c 79 20 27 6d 6f 75 6e 74 27 20 65 76 65 6e  nly 'mount' even
1010: 74 0a 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74  t..    tag.updat
1020: 65 28 7b 63 6f 6e 64 3a 20 74 72 75 65 7d 29 0a  e({cond: true}).
1030: 20 20 20 20 65 78 70 65 63 74 28 73 70 79 29 2e      expect(spy).
1040: 74 6f 2e 68 61 76 65 2e 62 65 65 6e 2e 63 61 6c  to.have.been.cal
1050: 6c 65 64 54 68 72 69 63 65 20 2f 2f 20 27 75 70  ledThrice // 'up
1060: 64 61 74 65 27 20 61 6e 64 20 27 75 70 64 61 74  date' and 'updat
1070: 65 64 27 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d  ed'..    tag.unm
1080: 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69  ount().  })..  i
1090: 74 28 27 43 75 73 74 6f 6d 20 74 61 67 73 20 77  t('Custom tags w
10a0: 69 74 68 20 61 6e 20 69 66 20 77 69 6c 6c 20 64  ith an if will d
10b0: 69 73 70 61 74 63 68 20 74 68 65 20 22 6d 6f 75  ispatch the "mou
10c0: 6e 74 22 20 65 76 65 6e 74 20 6f 6e 6c 79 20 77  nt" event only w
10d0: 68 65 6e 20 74 68 65 20 66 6c 61 67 20 69 73 27  hen the flag is'
10e0: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20  , function() {. 
10f0: 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c     injectHTML('<
1100: 72 69 6f 74 2d 74 6d 70 3e 3c 2f 72 69 6f 74 2d  riot-tmp></riot-
1110: 74 6d 70 3e 27 29 0a 20 20 20 20 72 69 6f 74 2e  tmp>').    riot.
1120: 74 61 67 28 27 69 6e 6e 65 72 27 2c 20 27 3c 62  tag('inner', '<b
1130: 72 3e 27 29 0a 20 20 20 20 72 69 6f 74 2e 74 61  r>').    riot.ta
1140: 67 28 27 72 69 6f 74 2d 74 6d 70 27 2c 20 27 3c  g('riot-tmp', '<
1150: 69 6e 6e 65 72 20 65 61 63 68 3d 22 7b 69 74 65  inner each="{ite
1160: 6d 20 69 6e 20 69 74 65 6d 73 7d 22 20 69 66 3d  m in items}" if=
1170: 22 7b 63 6f 6e 64 7d 22 20 2f 3e 27 2c 20 66 75  "{cond}" />', fu
1180: 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 20  nction() {.     
1190: 20 74 68 69 73 2e 69 74 65 6d 73 20 3d 20 5b 31   this.items = [1
11a0: 5d 0a 20 20 20 20 20 20 74 68 69 73 2e 63 6f 6e  ].      this.con
11b0: 64 20 3d 20 74 72 75 65 0a 20 20 20 20 7d 29 0a  d = true.    }).
11c0: 20 20 20 20 76 61 72 20 74 61 67 20 3d 20 72 69      var tag = ri
11d0: 6f 74 2e 6d 6f 75 6e 74 28 27 72 69 6f 74 2d 74  ot.mount('riot-t
11e0: 6d 70 27 29 5b 30 5d 0a 0a 20 20 20 20 65 78 70  mp')[0]..    exp
11f0: 65 63 74 48 54 4d 4c 28 74 61 67 29 2e 74 6f 2e  ectHTML(tag).to.
1200: 62 65 2e 65 71 75 61 6c 28 27 3c 69 6e 6e 65 72  be.equal('<inner
1210: 3e 3c 62 72 3e 3c 2f 69 6e 6e 65 72 3e 27 29 0a  ><br></inner>').
1220: 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74 65 28  .    tag.update(
1230: 7b 63 6f 6e 64 3a 20 66 61 6c 73 65 7d 29 0a 20  {cond: false}). 
1240: 20 20 20 65 78 70 65 63 74 48 54 4d 4c 28 74 61     expectHTML(ta
1250: 67 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  g).to.be.equal('
1260: 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61  ').    expect(ta
1270: 67 2e 74 61 67 73 2e 69 6e 6e 65 72 29 2e 74 6f  g.tags.inner).to
1280: 2e 62 65 2e 65 71 75 61 6c 28 75 6e 64 65 66 69  .be.equal(undefi
1290: 6e 65 64 29 0a 0a 20 20 20 20 74 61 67 2e 75 70  ned)..    tag.up
12a0: 64 61 74 65 28 7b 63 6f 6e 64 3a 20 74 72 75 65  date({cond: true
12b0: 7d 29 0a 20 20 20 20 65 78 70 65 63 74 48 54 4d  }).    expectHTM
12c0: 4c 28 74 61 67 29 2e 74 6f 2e 62 65 2e 65 71 75  L(tag).to.be.equ
12d0: 61 6c 28 27 3c 69 6e 6e 65 72 3e 3c 62 72 3e 3c  al('<inner><br><
12e0: 2f 69 6e 6e 65 72 3e 27 29 0a 20 20 20 20 65 78  /inner>').    ex
12f0: 70 65 63 74 28 74 61 67 2e 74 61 67 73 2e 69 6e  pect(tag.tags.in
1300: 6e 65 72 29 2e 6e 6f 74 2e 74 6f 2e 62 65 2e 65  ner).not.to.be.e
1310: 71 75 61 6c 28 75 6e 64 65 66 69 6e 65 64 29 0a  qual(undefined).
1320: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
1330: 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 43  ().  })..  it('C
1340: 75 73 74 6f 6d 20 74 61 67 73 20 77 69 74 68 20  ustom tags with 
1350: 61 6e 20 69 66 20 61 6e 64 20 6d 75 6c 74 69 70  an if and multip
1360: 6c 65 20 6d 69 78 69 6e 73 20 77 69 6c 6c 20 6e  le mixins will n
1370: 6f 74 20 74 68 72 6f 77 20 28 73 65 65 20 23 32  ot throw (see #2
1380: 31 30 30 29 27 2c 20 66 75 6e 63 74 69 6f 6e 28  100)', function(
1390: 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54  ) {.    injectHT
13a0: 4d 4c 28 27 3c 72 69 6f 74 2d 74 6d 70 3e 3c 2f  ML('<riot-tmp></
13b0: 72 69 6f 74 2d 74 6d 70 3e 27 29 0a 0a 20 20 20  riot-tmp>')..   
13c0: 20 76 61 72 20 6d 79 4d 69 78 69 6e 20 3d 20 7b   var myMixin = {
13d0: 7d 0a 20 20 20 20 76 61 72 20 6d 79 4d 69 78 69  }.    var myMixi
13e0: 6e 32 20 3d 20 7b 7d 0a 0a 20 20 20 20 72 69 6f  n2 = {}..    rio
13f0: 74 2e 74 61 67 28 27 69 6e 6e 65 72 27 2c 20 27  t.tag('inner', '
1400: 3c 64 69 76 3e 49 20 61 6d 20 63 68 69 6c 64 3c  <div>I am child<
1410: 2f 64 69 76 3e 27 2c 20 66 75 6e 63 74 69 6f 6e  /div>', function
1420: 28 29 20 7b 0a 20 20 20 20 20 20 74 68 69 73 2e  () {.      this.
1430: 6d 69 78 69 6e 28 6d 79 4d 69 78 69 6e 29 0a 20  mixin(myMixin). 
1440: 20 20 20 20 20 74 68 69 73 2e 6d 69 78 69 6e 28       this.mixin(
1450: 6d 79 4d 69 78 69 6e 32 29 0a 20 20 20 20 7d 29  myMixin2).    })
1460: 0a 0a 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27  ..    riot.tag('
1470: 72 69 6f 74 2d 74 6d 70 27 2c 20 27 3c 69 6e 6e  riot-tmp', '<inn
1480: 65 72 20 69 66 3d 22 7b 63 6f 6e 64 7d 22 20 2f  er if="{cond}" /
1490: 3e 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b  >', function() {
14a0: 0a 20 20 20 20 20 20 74 68 69 73 2e 63 6f 6e 64  .      this.cond
14b0: 20 3d 20 74 72 75 65 0a 20 20 20 20 7d 29 0a 0a   = true.    })..
14c0: 20 20 20 20 76 61 72 20 74 61 67 20 3d 20 72 69      var tag = ri
14d0: 6f 74 2e 6d 6f 75 6e 74 28 27 72 69 6f 74 2d 74  ot.mount('riot-t
14e0: 6d 70 27 29 5b 30 5d 0a 0a 20 20 20 20 65 78 70  mp')[0]..    exp
14f0: 65 63 74 48 54 4d 4c 28 74 61 67 29 2e 74 6f 2e  ectHTML(tag).to.
1500: 62 65 2e 65 71 75 61 6c 28 27 3c 69 6e 6e 65 72  be.equal('<inner
1510: 3e 3c 64 69 76 3e 49 20 61 6d 20 63 68 69 6c 64  ><div>I am child
1520: 3c 2f 64 69 76 3e 3c 2f 69 6e 6e 65 72 3e 27 29  </div></inner>')
1530: 0a 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74 65  ..    tag.update
1540: 28 7b 63 6f 6e 64 3a 20 66 61 6c 73 65 7d 29 0a  ({cond: false}).
1550: 20 20 20 20 65 78 70 65 63 74 48 54 4d 4c 28 74      expectHTML(t
1560: 61 67 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  ag).to.be.equal(
1570: 27 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 74  '').    expect(t
1580: 61 67 2e 74 61 67 73 2e 69 6e 6e 65 72 29 2e 74  ag.tags.inner).t
1590: 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e 64 65 66  o.be.equal(undef
15a0: 69 6e 65 64 29 0a 0a 20 20 20 20 74 61 67 2e 75  ined)..    tag.u
15b0: 70 64 61 74 65 28 7b 63 6f 6e 64 3a 20 74 72 75  pdate({cond: tru
15c0: 65 7d 29 0a 20 20 20 20 65 78 70 65 63 74 48 54  e}).    expectHT
15d0: 4d 4c 28 74 61 67 29 2e 74 6f 2e 62 65 2e 65 71  ML(tag).to.be.eq
15e0: 75 61 6c 28 27 3c 69 6e 6e 65 72 3e 3c 64 69 76  ual('<inner><div
15f0: 3e 49 20 61 6d 20 63 68 69 6c 64 3c 2f 64 69 76  >I am child</div
1600: 3e 3c 2f 69 6e 6e 65 72 3e 27 29 0a 20 20 20 20  ></inner>').    
1610: 65 78 70 65 63 74 28 74 61 67 2e 74 61 67 73 2e  expect(tag.tags.
1620: 69 6e 6e 65 72 29 2e 6e 6f 74 2e 74 6f 2e 62 65  inner).not.to.be
1630: 2e 65 71 75 61 6c 28 75 6e 64 65 66 69 6e 65 64  .equal(undefined
1640: 29 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75  )..    tag.unmou
1650: 6e 74 28 29 0a 20 20 7d 29 0a 0a 0a 20 20 69 74  nt().  })...  it
1660: 28 27 65 61 63 68 20 61 6e 6f 6e 79 6d 6f 75 73  ('each anonymous
1670: 20 77 69 74 68 20 61 6e 20 69 66 27 2c 20 66 75   with an if', fu
1680: 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 69  nction() {.    i
1690: 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 72 69 6f 74  njectHTML('<riot
16a0: 2d 74 6d 70 3e 3c 2f 72 69 6f 74 2d 74 6d 70 3e  -tmp></riot-tmp>
16b0: 27 29 0a 20 20 20 20 72 69 6f 74 2e 74 61 67 28  ').    riot.tag(
16c0: 27 72 69 6f 74 2d 74 6d 70 27 2c 20 60 0a 20 20  'riot-tmp', `.  
16d0: 20 20 20 20 3c 64 69 76 20 65 61 63 68 3d 22 7b      <div each="{
16e0: 69 74 65 6d 2c 20 69 20 69 6e 20 69 74 65 6d 73  item, i in items
16f0: 7d 22 20 69 66 3d 22 7b 69 74 65 6d 2e 63 6f 6e  }" if="{item.con
1700: 64 7d 22 3e 7b 69 7d 3c 2f 64 69 76 3e 0a 20 20  d}">{i}</div>.  
1710: 20 20 60 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20    `, function() 
1720: 7b 0a 20 20 20 20 20 20 74 68 69 73 2e 69 74 65  {.      this.ite
1730: 6d 73 20 3d 20 5b 7b 63 6f 6e 64 3a 20 74 72 75  ms = [{cond: tru
1740: 65 7d 2c 20 7b 63 6f 6e 64 3a 20 66 61 6c 73 65  e}, {cond: false
1750: 7d 5d 0a 20 20 20 20 7d 29 0a 20 20 20 20 76 61  }].    }).    va
1760: 72 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75  r tag = riot.mou
1770: 6e 74 28 27 72 69 6f 74 2d 74 6d 70 27 29 5b 30  nt('riot-tmp')[0
1780: 5d 0a 20 20 20 20 65 78 70 65 63 74 48 54 4d 4c  ].    expectHTML
1790: 28 74 61 67 29 2e 74 6f 2e 62 65 2e 65 71 75 61  (tag).to.be.equa
17a0: 6c 28 27 3c 64 69 76 3e 30 3c 2f 64 69 76 3e 27  l('<div>0</div>'
17b0: 29 0a 20 20 20 20 74 61 67 2e 69 74 65 6d 73 5b  ).    tag.items[
17c0: 31 5d 2e 63 6f 6e 64 20 3d 20 74 72 75 65 0a 20  1].cond = true. 
17d0: 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a     tag.update().
17e0: 20 20 20 20 65 78 70 65 63 74 48 54 4d 4c 28 74      expectHTML(t
17f0: 61 67 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  ag).to.be.equal(
1800: 27 3c 64 69 76 3e 30 3c 2f 64 69 76 3e 3c 64 69  '<div>0</div><di
1810: 76 3e 31 3c 2f 64 69 76 3e 27 29 0a 20 20 20 20  v>1</div>').    
1820: 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20  tag.unmount().  
1830: 7d 29 0a 0a 20 20 69 74 28 27 69 66 20 64 69 72  })..  it('if dir
1840: 65 63 74 69 76 65 20 6f 6e 20 61 20 73 65 6c 65  ective on a sele
1850: 63 74 20 73 68 6f 75 6c 64 20 75 70 64 61 74 65  ct should update
1860: 20 70 72 6f 70 65 72 6c 79 20 74 68 65 20 64 6f   properly the do
1870: 6d 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b  m', function() {
1880: 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28  .    injectHTML(
1890: 27 3c 62 75 67 2d 32 32 32 39 3e 3c 2f 62 75 67  '<bug-2229></bug
18a0: 2d 32 32 32 39 3e 27 29 0a 20 20 20 20 76 61 72  -2229>').    var
18b0: 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e   tag = riot.moun
18c0: 74 28 27 62 75 67 2d 32 32 32 39 27 29 5b 30 5d  t('bug-2229')[0]
18d0: 0a 0a 20 20 20 20 65 78 70 65 63 74 48 54 4d 4c  ..    expectHTML
18e0: 28 74 61 67 2e 72 6f 6f 74 29 2e 74 6f 2e 62 65  (tag.root).to.be
18f0: 2e 65 71 75 61 6c 28 27 3c 64 69 76 3e 3c 73 65  .equal('<div><se
1900: 6c 65 63 74 3e 3c 6f 70 74 69 6f 6e 20 76 61 6c  lect><option val
1910: 75 65 3d 22 31 22 3e 4f 6e 65 3c 2f 6f 70 74 69  ue="1">One</opti
1920: 6f 6e 3e 3c 6f 70 74 69 6f 6e 20 76 61 6c 75 65  on><option value
1930: 3d 22 32 22 3e 54 77 6f 3c 2f 6f 70 74 69 6f 6e  ="2">Two</option
1940: 3e 3c 2f 73 65 6c 65 63 74 3e 3c 2f 64 69 76 3e  ></select></div>
1950: 27 29 0a 20 20 20 20 74 61 67 2e 66 6c 61 67 20  ').    tag.flag 
1960: 3d 20 66 61 6c 73 65 0a 20 20 20 20 74 61 67 2e  = false.    tag.
1970: 75 70 64 61 74 65 28 29 0a 20 20 20 20 65 78 70  update().    exp
1980: 65 63 74 48 54 4d 4c 28 74 61 67 2e 72 6f 6f 74  ectHTML(tag.root
1990: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 3c  ).to.be.equal('<
19a0: 64 69 76 3e 3c 2f 64 69 76 3e 27 29 0a 20 20 20  div></div>').   
19b0: 20 74 61 67 2e 66 6c 61 67 20 3d 20 74 72 75 65   tag.flag = true
19c0: 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74 65 28  .    tag.update(
19d0: 29 0a 20 20 20 20 65 78 70 65 63 74 48 54 4d 4c  ).    expectHTML
19e0: 28 74 61 67 2e 72 6f 6f 74 29 2e 74 6f 2e 62 65  (tag.root).to.be
19f0: 2e 65 71 75 61 6c 28 27 3c 64 69 76 3e 3c 73 65  .equal('<div><se
1a00: 6c 65 63 74 3e 3c 6f 70 74 69 6f 6e 20 76 61 6c  lect><option val
1a10: 75 65 3d 22 31 22 3e 4f 6e 65 3c 2f 6f 70 74 69  ue="1">One</opti
1a20: 6f 6e 3e 3c 6f 70 74 69 6f 6e 20 76 61 6c 75 65  on><option value
1a30: 3d 22 32 22 3e 54 77 6f 3c 2f 6f 70 74 69 6f 6e  ="2">Two</option
1a40: 3e 3c 2f 73 65 6c 65 63 74 3e 3c 2f 64 69 76 3e  ></select></div>
1a50: 27 29 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f  ')..    tag.unmo
1a60: 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74  unt().  })..  it
1a70: 28 27 63 6f 6e 64 69 74 69 6f 6e 61 6c 20 63 75  ('conditional cu
1a80: 73 74 6f 6d 20 74 61 67 73 20 73 68 6f 75 6c 64  stom tags should
1a90: 6e 5c 27 74 20 64 69 73 70 61 74 63 68 20 6f 6e  n\'t dispatch on
1aa0: 6c 79 20 6f 6e 65 20 22 6d 6f 75 6e 74 22 20 65  ly one "mount" e
1ab0: 76 65 6e 74 20 69 66 20 74 6f 67 67 6c 65 64 20  vent if toggled 
1ac0: 6d 6f 75 6e 74 65 64 27 2c 20 28 29 20 3d 3e 20  mounted', () => 
1ad0: 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c  {.    injectHTML
1ae0: 28 27 3c 72 69 6f 74 2d 74 6d 70 3e 3c 2f 72 69  ('<riot-tmp></ri
1af0: 6f 74 2d 74 6d 70 3e 27 29 0a 20 20 20 20 63 6f  ot-tmp>').    co
1b00: 6e 73 74 20 6d 6f 75 6e 74 45 76 65 6e 74 20 3d  nst mountEvent =
1b10: 20 73 69 6e 6f 6e 2e 73 70 79 28 29 0a 0a 20 20   sinon.spy()..  
1b20: 20 20 72 69 6f 74 2e 74 61 67 28 27 72 69 6f 74    riot.tag('riot
1b30: 2d 74 6d 70 27 2c 20 60 0a 20 20 20 20 20 20 3c  -tmp', `.      <
1b40: 72 69 6f 74 2d 74 6d 70 2d 73 75 62 20 69 66 3d  riot-tmp-sub if=
1b50: 22 7b 20 73 68 6f 77 43 68 69 6c 64 20 7d 22 3e  "{ showChild }">
1b60: 3c 2f 72 69 6f 74 2d 74 6d 70 2d 73 75 62 3e 0a  </riot-tmp-sub>.
1b70: 20 20 20 20 20 20 3c 62 75 74 74 6f 6e 20 72 65        <button re
1b80: 66 3d 22 62 75 74 74 6f 6e 22 20 6f 6e 63 6c 69  f="button" oncli
1b90: 63 6b 3d 22 7b 20 74 6f 67 67 6c 65 20 7d 22 3e  ck="{ toggle }">
1ba0: 62 74 6e 3c 2f 62 75 74 74 6f 6e 3e 0a 20 20 20  btn</button>.   
1bb0: 20 60 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b   `, function() {
1bc0: 0a 20 20 20 20 20 20 74 68 69 73 2e 73 68 6f 77  .      this.show
1bd0: 43 68 69 6c 64 20 3d 20 74 72 75 65 0a 20 20 20  Child = true.   
1be0: 20 20 20 74 68 69 73 2e 6f 6e 28 27 6d 6f 75 6e     this.on('moun
1bf0: 74 27 2c 20 28 29 20 3d 3e 20 7b 0a 20 20 20 20  t', () => {.    
1c00: 20 20 20 20 74 68 69 73 2e 75 70 64 61 74 65 28      this.update(
1c10: 29 0a 20 20 20 20 20 20 7d 29 0a 20 20 20 20 20  ).      }).     
1c20: 20 74 68 69 73 2e 74 6f 67 67 6c 65 20 3d 20 28   this.toggle = (
1c30: 29 20 3d 3e 20 74 68 69 73 2e 75 70 64 61 74 65  ) => this.update
1c40: 28 29 0a 20 20 20 20 7d 29 0a 0a 20 20 20 20 72  ().    })..    r
1c50: 69 6f 74 2e 74 61 67 28 27 72 69 6f 74 2d 74 6d  iot.tag('riot-tm
1c60: 70 2d 73 75 62 27 2c 20 27 3c 70 3e 73 75 62 74  p-sub', '<p>subt
1c70: 61 67 3c 2f 70 3e 27 2c 20 66 75 6e 63 74 69 6f  ag</p>', functio
1c80: 6e 28 29 20 7b 0a 20 20 20 20 20 20 74 68 69 73  n() {.      this
1c90: 2e 6f 6e 28 27 6d 6f 75 6e 74 27 2c 20 6d 6f 75  .on('mount', mou
1ca0: 6e 74 45 76 65 6e 74 29 0a 20 20 20 20 7d 29 0a  ntEvent).    }).
1cb0: 0a 20 20 20 20 63 6f 6e 73 74 20 5b 74 61 67 5d  .    const [tag]
1cc0: 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 72   = riot.mount('r
1cd0: 69 6f 74 2d 74 6d 70 27 29 0a 0a 20 20 20 20 66  iot-tmp')..    f
1ce0: 69 72 65 45 76 65 6e 74 28 74 61 67 2e 72 65 66  ireEvent(tag.ref
1cf0: 73 2e 62 75 74 74 6f 6e 2c 20 27 63 6c 69 63 6b  s.button, 'click
1d00: 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 6d 6f  ').    expect(mo
1d10: 75 6e 74 45 76 65 6e 74 2c 20 27 6d 6f 75 6e 74  untEvent, 'mount
1d20: 20 65 76 65 6e 74 27 29 2e 74 6f 2e 68 61 76 65   event').to.have
1d30: 2e 62 65 65 6e 2e 63 61 6c 6c 65 64 4f 6e 63 65  .been.calledOnce
1d40: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
1d50: 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 6e  ().  })..  it('n
1d60: 65 73 74 65 64 20 69 66 20 69 6e 20 61 20 76 69  ested if in a vi
1d70: 72 74 75 61 6c 20 74 61 67 20 73 68 6f 75 6c 64  rtual tag should
1d80: 20 72 65 6e 64 65 72 20 70 72 6f 70 65 72 6c 79   render properly
1d90: 20 28 69 73 73 75 65 20 32 35 37 35 29 27 2c 20   (issue 2575)', 
1da0: 28 29 20 3d 3e 20 7b 0a 20 20 20 20 69 6e 6a 65  () => {.    inje
1db0: 63 74 48 54 4d 4c 28 27 3c 72 69 6f 74 2d 74 6d  ctHTML('<riot-tm
1dc0: 70 3e 3c 2f 72 69 6f 74 2d 74 6d 70 3e 27 29 0a  p></riot-tmp>').
1dd0: 0a 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27 72  .    riot.tag('r
1de0: 69 6f 74 2d 74 6d 70 27 2c 20 60 0a 20 20 20 20  iot-tmp', `.    
1df0: 20 20 3c 76 69 72 74 75 61 6c 20 69 66 3d 22 7b    <virtual if="{
1e00: 20 63 6f 6e 64 20 7d 22 3e 0a 20 20 20 20 20 20   cond }">.      
1e10: 20 20 3c 70 20 69 66 3d 22 7b 20 63 6f 6e 64 32    <p if="{ cond2
1e20: 20 7d 22 3e 48 65 6c 6c 6f 3c 2f 70 3e 0a 20 20   }">Hello</p>.  
1e30: 20 20 20 20 3c 2f 76 69 72 74 75 61 6c 3e 0a 20      </virtual>. 
1e40: 20 20 20 60 29 0a 0a 20 20 20 20 63 6f 6e 73 74     `)..    const
1e50: 20 5b 74 61 67 5d 20 3d 20 72 69 6f 74 2e 6d 6f   [tag] = riot.mo
1e60: 75 6e 74 28 27 72 69 6f 74 2d 74 6d 70 27 29 0a  unt('riot-tmp').
1e70: 0a 20 20 20 20 74 61 67 2e 63 6f 6e 64 20 3d 20  .    tag.cond = 
1e80: 74 72 75 65 0a 20 20 20 20 74 61 67 2e 63 6f 6e  true.    tag.con
1e90: 64 32 20 3d 20 74 72 75 65 0a 20 20 20 20 74 61  d2 = true.    ta
1ea0: 67 2e 75 70 64 61 74 65 28 29 0a 20 20 20 20 74  g.update().    t
1eb0: 61 67 2e 63 6f 6e 64 20 3d 20 66 61 6c 73 65 0a  ag.cond = false.
1ec0: 20 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 29      tag.update()
1ed0: 0a 20 20 20 20 74 61 67 2e 63 6f 6e 64 20 3d 20  .    tag.cond = 
1ee0: 74 72 75 65 0a 20 20 20 20 74 61 67 2e 75 70 64  true.    tag.upd
1ef0: 61 74 65 28 29 0a 20 20 20 20 65 78 70 65 63 74  ate().    expect
1f00: 28 24 24 28 27 70 27 2c 20 74 61 67 2e 72 6f 6f  ($$('p', tag.roo
1f10: 74 29 29 2e 74 6f 2e 68 61 76 65 2e 6c 65 6e 67  t)).to.have.leng
1f20: 74 68 28 31 29 0a 20 20 20 20 74 61 67 2e 75 6e  th(1).    tag.un
1f30: 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 20  mount().  })..  
1f40: 69 74 28 27 6e 65 73 74 65 64 20 69 66 20 73 68  it('nested if sh
1f50: 6f 75 6c 64 20 6e 6f 74 20 63 61 75 73 65 20 72  ould not cause r
1f60: 61 63 65 20 63 6f 6e 64 69 74 69 6f 6e 20 72 65  ace condition re
1f70: 6e 64 65 72 69 6e 67 20 69 73 73 75 65 73 20 28  ndering issues (
1f80: 69 73 73 75 65 20 32 36 30 39 29 27 2c 20 28 29  issue 2609)', ()
1f90: 20 3d 3e 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74   => {.    inject
1fa0: 48 54 4d 4c 28 27 3c 62 75 67 2d 32 36 30 39 3e  HTML('<bug-2609>
1fb0: 3c 2f 62 75 67 2d 32 36 30 39 3e 27 29 0a 0a 20  </bug-2609>').. 
1fc0: 20 20 20 63 6f 6e 73 74 20 5b 74 61 67 5d 20 3d     const [tag] =
1fd0: 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 62 75 67   riot.mount('bug
1fe0: 2d 32 36 30 39 27 29 0a 0a 20 20 20 20 65 78 70  -2609')..    exp
1ff0: 65 63 74 28 74 61 67 2e 6f 6e 43 6c 69 63 6b 29  ect(tag.onClick)
2000: 2e 74 6f 2e 6e 6f 74 2e 74 68 72 6f 77 28 29 0a  .to.not.throw().
2010: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
2020: 28 29 0a 20 20 7d 29 0a 7d 29 0a                 ().  }).}).