⌈⌋ ⎇ branch:  Bitrhythm


Hex Artifact Content

Artifact a48eeb6ea7e2c513eb87ce228474e3d7a9c71ab2488e2d20f946ca446e43ba1c:


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 24 24 2c 0a 20 20 24  tHTML,.  $$,.  $
0020: 2c 0a 20 20 49 45 5f 56 45 52 53 49 4f 4e 2c 0a  ,.  IE_VERSION,.
0030: 20 20 67 65 74 4e 65 78 74 53 69 62 6c 69 6e 67    getNextSibling
0040: 2c 0a 20 20 67 65 74 50 72 65 76 69 6f 75 73 53  ,.  getPreviousS
0050: 69 62 6c 69 6e 67 2c 0a 20 20 6e 6f 72 6d 61 6c  ibling,.  normal
0060: 69 7a 65 48 54 4d 4c 2c 0a 20 20 66 69 72 65 45  izeHTML,.  fireE
0070: 76 65 6e 74 2c 0a 7d 20 66 72 6f 6d 20 27 2e 2e  vent,.} from '..
0080: 2f 2e 2e 2f 2e 2e 2f 68 65 6c 70 65 72 73 2f 69  /../../helpers/i
0090: 6e 64 65 78 27 0a 0a 2f 2f 20 69 6e 63 6c 75 64  ndex'..// includ
00a0: 65 20 73 70 65 63 69 61 6c 20 74 61 67 73 20 74  e special tags t
00b0: 6f 20 74 65 73 74 20 73 70 65 63 69 66 69 63 20  o test specific 
00c0: 66 65 61 74 75 72 65 73 0a 69 6d 70 6f 72 74 20  features.import 
00d0: 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f  '../../../tag/lo
00e0: 6f 70 2d 73 76 67 2d 6e 6f 64 65 73 2e 74 61 67  op-svg-nodes.tag
00f0: 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f  '.import '../../
0100: 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 70 6f 73 69  ../tag/loop-posi
0110: 74 69 6f 6e 2e 74 61 67 27 0a 69 6d 70 6f 72 74  tion.tag'.import
0120: 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 74   '../../../tag/t
0130: 61 62 6c 65 2d 64 61 74 61 2e 74 61 67 27 0a 69  able-data.tag'.i
0140: 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f  mport '../../../
0150: 74 61 67 2f 6c 6f 6f 70 2d 6f 70 74 69 6f 6e 2e  tag/loop-option.
0160: 74 61 67 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f  tag'.import '../
0170: 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 6f  ../../tag/loop-o
0180: 70 74 67 72 6f 75 70 2e 74 61 67 27 0a 69 6d 70  ptgroup.tag'.imp
0190: 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61  ort '../../../ta
01a0: 67 2f 6c 6f 6f 70 2d 6f 70 74 67 72 6f 75 70 32  g/loop-optgroup2
01b0: 2e 74 61 67 27 0a 69 6d 70 6f 72 74 20 27 2e 2e  .tag'.import '..
01c0: 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d  /../../tag/loop-
01d0: 61 72 72 61 79 6c 69 6b 65 2e 74 61 67 27 0a 69  arraylike.tag'.i
01e0: 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f  mport '../../../
01f0: 74 61 67 2f 6c 6f 6f 70 2d 69 64 73 2e 74 61 67  tag/loop-ids.tag
0200: 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f  '.import '../../
0210: 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 75 6e 73 68  ../tag/loop-unsh
0220: 69 66 74 2e 74 61 67 27 0a 69 6d 70 6f 72 74 20  ift.tag'.import 
0230: 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f  '../../../tag/lo
0240: 6f 70 2d 76 69 72 74 75 61 6c 2e 74 61 67 27 0a  op-virtual.tag'.
0250: 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e  import '../../..
0260: 2f 74 61 67 2f 6c 6f 6f 70 2d 6e 75 6c 6c 2d 69  /tag/loop-null-i
0270: 74 65 6d 73 2e 74 61 67 27 0a 69 6d 70 6f 72 74  tems.tag'.import
0280: 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c   '../../../tag/l
0290: 6f 6f 70 2d 6e 61 6d 65 64 2e 74 61 67 27 0a 69  oop-named.tag'.i
02a0: 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f  mport '../../../
02b0: 74 61 67 2f 6c 6f 6f 70 2d 73 69 6e 67 6c 65 2d  tag/loop-single-
02c0: 74 61 67 73 2e 74 61 67 27 0a 69 6d 70 6f 72 74  tags.tag'.import
02d0: 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c   '../../../tag/l
02e0: 6f 6f 70 2e 74 61 67 27 0a 69 6d 70 6f 72 74 20  oop.tag'.import 
02f0: 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f  '../../../tag/lo
0300: 6f 70 2d 63 6f 6c 73 2e 74 61 67 27 0a 69 6d 70  op-cols.tag'.imp
0310: 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61  ort '../../../ta
0320: 67 2f 6c 6f 6f 70 2d 63 68 69 6c 64 2e 74 61 67  g/loop-child.tag
0330: 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f  '.import '../../
0340: 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 63 6f 6d 62  ../tag/loop-comb
0350: 6f 2e 74 61 67 27 0a 69 6d 70 6f 72 74 20 27 2e  o.tag'.import '.
0360: 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f 6f 70  ./../../tag/loop
0370: 2d 72 65 6f 72 64 65 72 2e 74 61 67 27 0a 69 6d  -reorder.tag'.im
0380: 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74  port '../../../t
0390: 61 67 2f 6c 6f 6f 70 2d 73 77 61 70 2d 74 79 70  ag/loop-swap-typ
03a0: 65 2e 74 61 67 27 0a 69 6d 70 6f 72 74 20 27 2e  e.tag'.import '.
03b0: 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f 6f 70  ./../../tag/loop
03c0: 2d 6d 61 6e 69 70 2e 74 61 67 27 0a 69 6d 70 6f  -manip.tag'.impo
03d0: 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67  rt '../../../tag
03e0: 2f 6c 6f 6f 70 2d 6f 62 6a 65 63 74 2e 74 61 67  /loop-object.tag
03f0: 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f  '.import '../../
0400: 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 6f 62 6a 65  ../tag/loop-obje
0410: 63 74 2d 63 6f 6e 64 69 74 69 6f 6e 61 6c 2e 74  ct-conditional.t
0420: 61 67 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e  ag'.import '../.
0430: 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 74 61  ./../tag/loop-ta
0440: 67 2d 69 6e 73 74 61 6e 63 65 73 2e 74 61 67 27  g-instances.tag'
0450: 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e  .import '../../.
0460: 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 6e 65 73 74 65  ./tag/loop-neste
0470: 64 2e 74 61 67 27 0a 69 6d 70 6f 72 74 20 27 2e  d.tag'.import '.
0480: 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f 6f 70  ./../../tag/loop
0490: 2d 6e 75 6d 62 65 72 73 2d 6e 65 73 74 65 64 2e  -numbers-nested.
04a0: 74 61 67 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f  tag'.import '../
04b0: 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 6e  ../../tag/loop-n
04c0: 65 73 74 65 64 2d 73 74 72 69 6e 67 73 2d 61 72  ested-strings-ar
04d0: 72 61 79 2e 74 61 67 27 0a 69 6d 70 6f 72 74 20  ray.tag'.import 
04e0: 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f  '../../../tag/lo
04f0: 6f 70 2d 65 76 65 6e 74 73 2e 74 61 67 27 0a 69  op-events.tag'.i
0500: 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f  mport '../../../
0510: 74 61 67 2f 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70  tag/loop-sync-op
0520: 74 69 6f 6e 73 2d 6e 65 73 74 65 64 2e 74 61 67  tions-nested.tag
0530: 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f  '.import '../../
0540: 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 69 6e 68 65  ../tag/loop-inhe
0550: 72 69 74 2e 74 61 67 27 0a 69 6d 70 6f 72 74 20  rit.tag'.import 
0560: 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f  '../../../tag/lo
0570: 6f 70 2d 72 6f 6f 74 2e 74 61 67 27 0a 69 6d 70  op-root.tag'.imp
0580: 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61  ort '../../../ta
0590: 67 2f 6c 6f 6f 70 2d 64 6f 75 62 6c 65 2d 63 75  g/loop-double-cu
05a0: 72 6c 79 2d 62 72 61 63 6b 65 74 73 2e 74 61 67  rly-brackets.tag
05b0: 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f  '.import '../../
05c0: 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 63 6f 6e 64  ../tag/loop-cond
05d0: 69 74 69 6f 6e 61 6c 2e 74 61 67 27 0a 69 6d 70  itional.tag'.imp
05e0: 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61  ort '../../../ta
05f0: 67 2f 6c 6f 6f 70 2d 70 72 6f 74 65 63 74 2d 69  g/loop-protect-i
0600: 6e 74 65 72 6e 61 6c 2d 61 74 74 72 73 2e 74 61  nternal-attrs.ta
0610: 67 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e  g'.import '../..
0620: 2f 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 6e 6f 6c  /../tag/loop-nol
0630: 6f 6f 70 2d 6f 70 74 69 6f 6e 2e 74 61 67 27 0a  oop-option.tag'.
0640: 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e  import '../../..
0650: 2f 74 61 67 2f 6c 6f 6f 70 2d 69 74 65 6d 73 2d  /tag/loop-items-
0660: 61 74 74 72 73 2e 74 61 67 27 0a 69 6d 70 6f 72  attrs.tag'.impor
0670: 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f  t '../../../tag/
0680: 70 6c 6f 6f 70 2d 74 61 67 2e 74 61 67 27 0a 69  ploop-tag.tag'.i
0690: 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f  mport '../../../
06a0: 74 61 67 2f 74 61 62 6c 65 2d 6c 6f 6f 70 2d 65  tag/table-loop-e
06b0: 78 74 72 61 2d 72 6f 77 2e 74 61 67 27 0a 69 6d  xtra-row.tag'.im
06c0: 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74  port '../../../t
06d0: 61 67 2f 6f 62 6a 2d 6b 65 79 2d 6c 6f 6f 70 2e  ag/obj-key-loop.
06e0: 74 61 67 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f  tag'.import '../
06f0: 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 73  ../../tag/loop-s
0700: 79 6e 63 2d 6f 70 74 69 6f 6e 73 2e 74 61 67 27  ync-options.tag'
0710: 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e  .import '../../.
0720: 2e 2f 74 61 67 2f 6f 75 74 65 72 2e 74 61 67 27  ./tag/outer.tag'
0730: 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e  .import '../../.
0740: 2e 2f 74 61 67 2f 72 65 73 65 72 76 65 64 2d 6e  ./tag/reserved-n
0750: 61 6d 65 73 2e 74 61 67 27 0a 69 6d 70 6f 72 74  ames.tag'.import
0760: 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c   '../../../tag/l
0770: 6f 6f 70 2d 62 75 67 2d 31 36 34 39 2e 74 61 67  oop-bug-1649.tag
0780: 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f  '.import '../../
0790: 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 62 75 67 2d  ../tag/loop-bug-
07a0: 32 32 30 35 2e 74 61 67 27 0a 69 6d 70 6f 72 74  2205.tag'.import
07b0: 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 6c   '../../../tag/l
07c0: 6f 6f 70 2d 62 75 67 2d 32 32 34 30 2e 74 61 67  oop-bug-2240.tag
07d0: 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f  '.import '../../
07e0: 2e 2e 2f 74 61 67 2f 6c 6f 6f 70 2d 62 75 67 2d  ../tag/loop-bug-
07f0: 32 32 34 32 2e 74 61 67 27 0a 0a 69 6d 70 6f 72  2242.tag'..impor
0800: 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f  t '../../../tag/
0810: 73 65 6c 65 63 74 2d 74 65 73 74 2e 74 61 67 27  select-test.tag'
0820: 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e  .import '../../.
0830: 2e 2f 74 61 67 2f 6e 61 6d 65 64 2d 73 65 6c 65  ./tag/named-sele
0840: 63 74 2e 74 61 67 27 0a 0a 69 6d 70 6f 72 74 20  ct.tag'..import 
0850: 27 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 74 61  '../../../tag/ta
0860: 62 6c 65 2d 74 68 65 61 64 2d 74 66 6f 6f 74 2e  ble-thead-tfoot.
0870: 74 61 67 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f  tag'.import '../
0880: 2e 2e 2f 2e 2e 2f 74 61 67 2f 74 61 62 6c 65 2d  ../../tag/table-
0890: 6d 75 6c 74 69 62 6f 64 79 2e 74 61 67 27 0a 69  multibody.tag'.i
08a0: 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f 2e 2e 2f  mport '../../../
08b0: 74 61 67 2f 74 61 62 6c 65 2d 74 68 65 61 64 2d  tag/table-thead-
08c0: 74 66 6f 6f 74 2d 6e 65 73 74 65 64 2e 74 61 67  tfoot-nested.tag
08d0: 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f  '.import '../../
08e0: 2e 2e 2f 74 61 67 2f 74 61 62 6c 65 2d 74 65 73  ../tag/table-tes
08f0: 74 2e 74 61 67 27 0a 0a 69 6d 70 6f 72 74 20 27  t.tag'..import '
0900: 2e 2e 2f 2e 2e 2f 2e 2e 2f 74 61 67 2f 76 69 72  ../../../tag/vir
0910: 74 75 61 6c 2d 6e 6f 2d 6c 6f 6f 70 2e 74 61 67  tual-no-loop.tag
0920: 27 0a 69 6d 70 6f 72 74 20 27 2e 2e 2f 2e 2e 2f  '.import '../../
0930: 2e 2e 2f 74 61 67 2f 76 69 72 74 75 61 6c 2d 79  ../tag/virtual-y
0940: 69 65 6c 64 2d 6c 6f 6f 70 2e 74 61 67 27 0a 0a  ield-loop.tag'..
0950: 64 65 73 63 72 69 62 65 28 27 52 69 6f 74 20 65  describe('Riot e
0960: 61 63 68 20 6e 6f 74 20 6b 65 79 65 64 27 2c 20  ach not keyed', 
0970: 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 69  function() {.  i
0980: 74 28 27 74 68 65 20 6c 6f 6f 70 20 65 6c 65 6d  t('the loop elem
0990: 65 6e 74 73 20 6b 65 65 70 20 74 68 65 69 72 20  ents keep their 
09a0: 70 6f 73 69 74 69 6f 6e 20 69 6e 20 74 68 65 20  position in the 
09b0: 44 4f 4d 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29  DOM', function()
09c0: 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d   {.    injectHTM
09d0: 4c 28 27 3c 6c 6f 6f 70 2d 70 6f 73 69 74 69 6f  L('<loop-positio
09e0: 6e 3e 3c 2f 6c 6f 6f 70 2d 70 6f 73 69 74 69 6f  n></loop-positio
09f0: 6e 3e 27 29 0a 20 20 20 20 63 6f 6e 73 74 20 74  n>').    const t
0a00: 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28  ag = riot.mount(
0a10: 27 6c 6f 6f 70 2d 70 6f 73 69 74 69 6f 6e 27 29  'loop-position')
0a20: 5b 30 5d 2c 0a 20 20 20 20 20 20 68 33 20 3d 20  [0],.      h3 = 
0a30: 24 28 27 68 33 27 2c 20 74 61 67 2e 72 6f 6f 74  $('h3', tag.root
0a40: 29 0a 0a 20 20 20 20 65 78 70 65 63 74 28 67 65  )..    expect(ge
0a50: 74 50 72 65 76 69 6f 75 73 53 69 62 6c 69 6e 67  tPreviousSibling
0a60: 28 68 33 29 2e 74 61 67 4e 61 6d 65 2e 74 6f 4c  (h3).tagName.toL
0a70: 6f 77 65 72 43 61 73 65 28 29 29 2e 74 6f 2e 62  owerCase()).to.b
0a80: 65 2e 65 71 75 61 6c 28 27 70 27 29 0a 20 20 20  e.equal('p').   
0a90: 20 65 78 70 65 63 74 28 67 65 74 4e 65 78 74 53   expect(getNextS
0aa0: 69 62 6c 69 6e 67 28 68 33 29 2e 74 61 67 4e 61  ibling(h3).tagNa
0ab0: 6d 65 2e 74 6f 4c 6f 77 65 72 43 61 73 65 28 29  me.toLowerCase()
0ac0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 70  ).to.be.equal('p
0ad0: 27 29 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f  ')..    tag.unmo
0ae0: 75 6e 74 28 29 0a 0a 20 20 7d 29 0a 0a 20 20 69  unt()..  })..  i
0af0: 74 28 27 53 56 47 73 20 6e 6f 64 65 73 20 63 61  t('SVGs nodes ca
0b00: 6e 20 62 65 20 70 72 6f 70 65 72 6c 79 20 6c 6f  n be properly lo
0b10: 6f 70 65 64 27 2c 20 66 75 6e 63 74 69 6f 6e 28  oped', function(
0b20: 29 20 7b 0a 0a 20 20 20 20 69 6e 6a 65 63 74 48  ) {..    injectH
0b30: 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 73 76 67 2d 6e  TML('<loop-svg-n
0b40: 6f 64 65 73 3e 3c 2f 6c 6f 6f 70 2d 73 76 67 2d  odes></loop-svg-
0b50: 6e 6f 64 65 73 3e 27 29 0a 0a 20 20 20 20 63 6f  nodes>')..    co
0b60: 6e 73 74 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d  nst tag = riot.m
0b70: 6f 75 6e 74 28 27 6c 6f 6f 70 2d 73 76 67 2d 6e  ount('loop-svg-n
0b80: 6f 64 65 73 27 29 5b 30 5d 0a 0a 20 20 20 20 65  odes')[0]..    e
0b90: 78 70 65 63 74 28 24 24 28 27 73 76 67 20 63 69  xpect($$('svg ci
0ba0: 72 63 6c 65 27 2c 20 74 61 67 2e 72 6f 6f 74 29  rcle', tag.root)
0bb0: 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65  .length).to.be.e
0bc0: 71 75 61 6c 28 35 29 0a 20 20 20 20 65 78 70 65  qual(5).    expe
0bd0: 63 74 28 24 28 27 73 76 67 20 63 69 72 63 6c 65  ct($('svg circle
0be0: 27 2c 20 20 74 61 67 2e 72 6f 6f 74 29 2e 6f 77  ',  tag.root).ow
0bf0: 6e 65 72 53 56 47 45 6c 65 6d 65 6e 74 29 2e 74  nerSVGElement).t
0c00: 6f 2e 62 65 2e 6f 6b 0a 20 20 20 20 65 78 70 65  o.be.ok.    expe
0c10: 63 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f  ct(tag.tags['loo
0c20: 70 2d 73 76 67 2d 6e 6f 64 65 73 2d 63 75 73 74  p-svg-nodes-cust
0c30: 6f 6d 2d 63 69 72 63 6c 65 27 5d 5b 30 5d 2e 72  om-circle'][0].r
0c40: 65 66 73 2e 63 69 72 63 6c 65 2e 6f 77 6e 65 72  efs.circle.owner
0c50: 53 56 47 45 6c 65 6d 65 6e 74 29 2e 74 6f 2e 62  SVGElement).to.b
0c60: 65 2e 6f 6b 0a 20 20 20 20 65 78 70 65 63 74 28  e.ok.    expect(
0c70: 24 28 27 70 27 2c 20 20 74 61 67 2e 72 6f 6f 74  $('p',  tag.root
0c80: 29 20 69 6e 73 74 61 6e 63 65 6f 66 20 48 54 4d  ) instanceof HTM
0c90: 4c 45 6c 65 6d 65 6e 74 29 2e 74 6f 2e 62 65 2e  LElement).to.be.
0ca0: 65 71 75 61 6c 28 74 72 75 65 29 0a 0a 20 20 20  equal(true)..   
0cb0: 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20   tag.unmount(). 
0cc0: 20 7d 29 0a 0a 20 20 69 74 28 27 74 68 65 20 72   })..  it('the r
0cd0: 6f 6f 74 20 6b 65 79 77 6f 72 64 20 73 68 6f 75  oot keyword shou
0ce0: 6c 64 20 62 65 20 70 72 6f 74 65 63 74 65 64 20  ld be protected 
0cf0: 61 6c 73 6f 20 69 6e 20 74 68 65 20 6c 6f 6f 70  also in the loop
0d00: 73 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b  s', function() {
0d10: 0a 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c  ..    injectHTML
0d20: 28 27 3c 6c 6f 6f 70 2d 72 6f 6f 74 3e 3c 2f 6c  ('<loop-root></l
0d30: 6f 6f 70 2d 72 6f 6f 74 3e 27 29 0a 20 20 20 20  oop-root>').    
0d40: 63 6f 6e 73 74 20 74 61 67 20 3d 20 72 69 6f 74  const tag = riot
0d50: 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d 72 6f 6f  .mount('loop-roo
0d60: 74 27 29 5b 30 5d 0a 0a 20 20 20 20 65 78 70 65  t')[0]..    expe
0d70: 63 74 28 24 24 28 27 6c 69 27 2c 20 74 61 67 2e  ct($$('li', tag.
0d80: 72 6f 6f 74 29 2e 6c 65 6e 67 74 68 29 2e 74 6f  root).length).to
0d90: 2e 62 65 2e 65 71 75 61 6c 28 33 29 0a 0a 20 20  .be.equal(3)..  
0da0: 20 20 74 61 67 2e 73 70 6c 69 63 65 28 29 0a 20    tag.splice(). 
0db0: 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a     tag.update().
0dc0: 0a 20 20 20 20 65 78 70 65 63 74 28 24 24 28 27  .    expect($$('
0dd0: 6c 69 27 2c 20 74 61 67 2e 72 6f 6f 74 29 2e 6c  li', tag.root).l
0de0: 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75  ength).to.be.equ
0df0: 61 6c 28 32 29 0a 0a 20 20 20 20 74 61 67 2e 75  al(2)..    tag.u
0e00: 6e 6d 6f 75 6e 74 28 29 0a 0a 20 20 7d 29 0a 0a  nmount()..  })..
0e10: 20 20 69 74 28 27 61 76 6f 69 64 20 74 6f 20 64    it('avoid to d
0e20: 75 70 6c 69 63 61 74 65 20 74 61 67 73 20 69 6e  uplicate tags in
0e30: 20 6d 75 6c 74 69 70 6c 65 20 66 6f 72 65 61 63   multiple foreac
0e40: 68 20 6c 6f 6f 70 73 27 2c 20 66 75 6e 63 74 69  h loops', functi
0e50: 6f 6e 28 29 20 7b 0a 0a 20 20 20 20 69 6e 6a 65  on() {..    inje
0e60: 63 74 48 54 4d 4c 28 5b 0a 20 20 20 20 20 20 27  ctHTML([.      '
0e70: 3c 6f 75 74 65 72 20 69 64 3d 22 6f 75 74 65 72  <outer id="outer
0e80: 31 22 3e 3c 2f 6f 75 74 65 72 3e 27 2c 0a 20 20  1"></outer>',.  
0e90: 20 20 20 20 27 3c 6f 75 74 65 72 20 69 64 3d 22      '<outer id="
0ea0: 6f 75 74 65 72 32 22 3e 3c 2f 6f 75 74 65 72 3e  outer2"></outer>
0eb0: 27 2c 0a 20 20 20 20 20 20 27 3c 6f 75 74 65 72  ',.      '<outer
0ec0: 20 69 64 3d 22 6f 75 74 65 72 33 22 3e 3c 2f 6f   id="outer3"></o
0ed0: 75 74 65 72 3e 27 0a 20 20 20 20 5d 29 0a 0a 20  uter>'.    ]).. 
0ee0: 20 20 20 76 61 72 20 6d 6f 75 6e 74 54 61 67 20     var mountTag 
0ef0: 3d 20 66 75 6e 63 74 69 6f 6e 28 74 61 67 49 64  = function(tagId
0f00: 29 20 7b 0a 20 20 20 20 20 20 76 61 72 20 64 61  ) {.      var da
0f10: 74 61 20 3d 20 5b 5d 2c 0a 20 20 20 20 20 20 20  ta = [],.       
0f20: 20 74 61 67 2c 0a 20 20 20 20 20 20 20 20 69 74   tag,.        it
0f30: 65 6d 73 43 6f 75 6e 74 20 3d 20 35 0a 0a 20 20  emsCount = 5..  
0f40: 20 20 20 20 77 68 69 6c 65 20 28 69 74 65 6d 73      while (items
0f50: 43 6f 75 6e 74 2d 2d 29 20 7b 0a 20 20 20 20 20  Count--) {.     
0f60: 20 20 20 64 61 74 61 2e 70 75 73 68 28 7b 0a 20     data.push({. 
0f70: 20 20 20 20 20 20 20 20 20 76 61 6c 75 65 3a 20           value: 
0f80: 27 69 74 65 6d 20 23 27 20 2b 20 69 74 65 6d 73  'item #' + items
0f90: 43 6f 75 6e 74 0a 20 20 20 20 20 20 20 20 7d 29  Count.        })
0fa0: 0a 20 20 20 20 20 20 7d 0a 0a 20 20 20 20 20 20  .      }..      
0fb0: 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74  tag = riot.mount
0fc0: 28 74 61 67 49 64 2c 20 7b 64 61 74 61 3a 20 64  (tagId, {data: d
0fd0: 61 74 61 7d 29 5b 30 5d 0a 20 20 20 20 20 20 2f  ata})[0].      /
0fe0: 2f 20 63 6f 6d 6d 65 6e 74 20 74 68 65 20 66 6f  / comment the fo
0ff0: 6c 6c 6f 77 69 6e 67 20 6c 69 6e 65 20 74 6f 20  llowing line to 
1000: 63 68 65 63 6b 20 74 68 65 20 72 65 6e 64 65 72  check the render
1010: 65 64 20 68 74 6d 6c 0a 0a 20 20 20 20 20 20 72  ed html..      r
1020: 65 74 75 72 6e 20 74 61 67 0a 0a 20 20 20 20 7d  eturn tag..    }
1030: 0a 0a 20 20 20 20 76 61 72 20 6f 75 74 65 72 31  ..    var outer1
1040: 20 3d 20 6d 6f 75 6e 74 54 61 67 28 27 23 6f 75   = mountTag('#ou
1050: 74 65 72 31 27 29 2c 0a 20 20 20 20 20 20 6f 75  ter1'),.      ou
1060: 74 65 72 32 20 3d 20 6d 6f 75 6e 74 54 61 67 28  ter2 = mountTag(
1070: 27 23 6f 75 74 65 72 32 27 29 2c 0a 20 20 20 20  '#outer2'),.    
1080: 20 20 6f 75 74 65 72 33 20 3d 20 6d 6f 75 6e 74    outer3 = mount
1090: 54 61 67 28 27 23 6f 75 74 65 72 33 27 29 0a 0a  Tag('#outer3')..
10a0: 20 20 20 20 65 78 70 65 63 74 28 6f 75 74 65 72      expect(outer
10b0: 31 2e 72 6f 6f 74 2e 67 65 74 45 6c 65 6d 65 6e  1.root.getElemen
10c0: 74 73 42 79 54 61 67 4e 61 6d 65 28 27 6f 75 74  tsByTagName('out
10d0: 65 72 2d 69 6e 6e 65 72 27 29 2e 6c 65 6e 67 74  er-inner').lengt
10e0: 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 35  h).to.be.equal(5
10f0: 29 0a 20 20 20 20 65 78 70 65 63 74 28 6f 75 74  ).    expect(out
1100: 65 72 31 2e 72 6f 6f 74 2e 67 65 74 45 6c 65 6d  er1.root.getElem
1110: 65 6e 74 73 42 79 54 61 67 4e 61 6d 65 28 27 73  entsByTagName('s
1120: 70 61 6e 27 29 2e 6c 65 6e 67 74 68 29 2e 74 6f  pan').length).to
1130: 2e 62 65 2e 65 71 75 61 6c 28 35 29 0a 20 20 20  .be.equal(5).   
1140: 20 65 78 70 65 63 74 28 6f 75 74 65 72 31 2e 72   expect(outer1.r
1150: 6f 6f 74 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42  oot.getElementsB
1160: 79 54 61 67 4e 61 6d 65 28 27 70 27 29 2e 6c 65  yTagName('p').le
1170: 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61  ngth).to.be.equa
1180: 6c 28 35 29 0a 20 20 20 20 65 78 70 65 63 74 28  l(5).    expect(
1190: 6f 75 74 65 72 32 2e 72 6f 6f 74 2e 67 65 74 45  outer2.root.getE
11a0: 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65  lementsByTagName
11b0: 28 27 6f 75 74 65 72 2d 69 6e 6e 65 72 27 29 2e  ('outer-inner').
11c0: 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71  length).to.be.eq
11d0: 75 61 6c 28 35 29 0a 20 20 20 20 65 78 70 65 63  ual(5).    expec
11e0: 74 28 6f 75 74 65 72 32 2e 72 6f 6f 74 2e 67 65  t(outer2.root.ge
11f0: 74 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61  tElementsByTagNa
1200: 6d 65 28 27 73 70 61 6e 27 29 2e 6c 65 6e 67 74  me('span').lengt
1210: 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 35  h).to.be.equal(5
1220: 29 0a 20 20 20 20 65 78 70 65 63 74 28 6f 75 74  ).    expect(out
1230: 65 72 32 2e 72 6f 6f 74 2e 67 65 74 45 6c 65 6d  er2.root.getElem
1240: 65 6e 74 73 42 79 54 61 67 4e 61 6d 65 28 27 70  entsByTagName('p
1250: 27 29 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65  ').length).to.be
1260: 2e 65 71 75 61 6c 28 35 29 0a 20 20 20 20 65 78  .equal(5).    ex
1270: 70 65 63 74 28 6f 75 74 65 72 33 2e 72 6f 6f 74  pect(outer3.root
1280: 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61  .getElementsByTa
1290: 67 4e 61 6d 65 28 27 6f 75 74 65 72 2d 69 6e 6e  gName('outer-inn
12a0: 65 72 27 29 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e  er').length).to.
12b0: 62 65 2e 65 71 75 61 6c 28 35 29 0a 20 20 20 20  be.equal(5).    
12c0: 65 78 70 65 63 74 28 6f 75 74 65 72 33 2e 72 6f  expect(outer3.ro
12d0: 6f 74 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79  ot.getElementsBy
12e0: 54 61 67 4e 61 6d 65 28 27 73 70 61 6e 27 29 2e  TagName('span').
12f0: 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71  length).to.be.eq
1300: 75 61 6c 28 35 29 0a 20 20 20 20 65 78 70 65 63  ual(5).    expec
1310: 74 28 6f 75 74 65 72 33 2e 72 6f 6f 74 2e 67 65  t(outer3.root.ge
1320: 74 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61  tElementsByTagNa
1330: 6d 65 28 27 70 27 29 2e 6c 65 6e 67 74 68 29 2e  me('p').length).
1340: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 35 29 0a 0a  to.be.equal(5)..
1350: 20 20 20 20 6f 75 74 65 72 31 2e 75 6e 6d 6f 75      outer1.unmou
1360: 6e 74 28 29 0a 20 20 20 20 6f 75 74 65 72 32 2e  nt().    outer2.
1370: 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 20 20 6f 75  unmount().    ou
1380: 74 65 72 33 2e 75 6e 6d 6f 75 6e 74 28 29 0a 0a  ter3.unmount()..
1390: 20 20 7d 29 0a 0a 20 20 69 74 28 27 74 68 65 20    })..  it('the 
13a0: 65 61 63 68 20 6c 6f 6f 70 73 20 75 70 64 61 74  each loops updat
13b0: 65 20 63 6f 72 72 65 63 74 6c 79 20 74 68 65 20  e correctly the 
13c0: 44 4f 4d 20 6e 6f 64 65 73 27 2c 20 66 75 6e 63  DOM nodes', func
13d0: 74 69 6f 6e 28 29 20 7b 0a 0a 20 20 20 20 69 6e  tion() {..    in
13e0: 6a 65 63 74 48 54 4d 4c 28 27 3c 6c 6f 6f 70 3e  jectHTML('<loop>
13f0: 3c 2f 6c 6f 6f 70 3e 27 29 0a 0a 20 20 20 20 76  </loop>')..    v
1400: 61 72 20 6f 6e 49 74 65 6d 43 6c 69 63 6b 20 3d  ar onItemClick =
1410: 20 66 75 6e 63 74 69 6f 6e 28 65 29 20 7b 0a 20   function(e) {. 
1420: 20 20 20 20 20 20 20 76 61 72 20 65 6c 49 6e 64         var elInd
1430: 65 78 20 3d 20 41 72 72 61 79 2e 70 72 6f 74 6f  ex = Array.proto
1440: 74 79 70 65 2e 73 6c 69 63 65 2e 63 61 6c 6c 28  type.slice.call(
1450: 63 68 69 6c 64 72 65 6e 29 2e 69 6e 64 65 78 4f  children).indexO
1460: 66 28 65 2e 63 75 72 72 65 6e 74 54 61 72 67 65  f(e.currentTarge
1470: 74 29 0a 20 20 20 20 20 20 20 20 65 78 70 65 63  t).        expec
1480: 74 28 74 61 67 2e 69 74 65 6d 73 5b 65 6c 49 6e  t(tag.items[elIn
1490: 64 65 78 5d 29 2e 74 6f 2e 62 65 2e 65 71 75 61  dex]).to.be.equa
14a0: 6c 28 65 2e 69 74 65 6d 2e 69 74 65 6d 29 0a 20  l(e.item.item). 
14b0: 20 20 20 20 20 7d 2c 0a 20 20 20 20 20 20 72 65       },.      re
14c0: 6d 6f 76 65 49 74 65 6d 43 6c 69 63 6b 20 3d 20  moveItemClick = 
14d0: 66 75 6e 63 74 69 6f 6e 28 65 29 20 7b 0a 20 20  function(e) {.  
14e0: 20 20 20 20 20 20 76 61 72 20 69 6e 64 65 78 20        var index 
14f0: 3d 20 74 61 67 2e 72 65 6d 6f 76 65 73 2e 69 6e  = tag.removes.in
1500: 64 65 78 4f 66 28 65 2e 69 74 65 6d 29 0a 20 20  dexOf(e.item).  
1510: 20 20 20 20 20 20 69 66 20 28 69 6e 64 65 78 20        if (index 
1520: 3c 20 30 29 20 72 65 74 75 72 6e 0a 20 20 20 20  < 0) return.    
1530: 20 20 20 20 74 61 67 2e 72 65 6d 6f 76 65 73 2e      tag.removes.
1540: 73 70 6c 69 63 65 28 69 6e 64 65 78 2c 20 31 29  splice(index, 1)
1550: 0a 20 20 20 20 20 20 7d 2c 0a 20 20 20 20 20 20  .      },.      
1560: 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74  tag = riot.mount
1570: 28 27 6c 6f 6f 70 27 2c 20 7b 20 6f 6e 49 74 65  ('loop', { onIte
1580: 6d 43 6c 69 63 6b 3a 20 6f 6e 49 74 65 6d 43 6c  mClick: onItemCl
1590: 69 63 6b 2c 20 72 65 6d 6f 76 65 49 74 65 6d 43  ick, removeItemC
15a0: 6c 69 63 6b 3a 20 72 65 6d 6f 76 65 49 74 65 6d  lick: removeItem
15b0: 43 6c 69 63 6b 20 7d 29 5b 30 5d 2c 0a 20 20 20  Click })[0],.   
15c0: 20 20 20 72 6f 6f 74 20 3d 20 74 61 67 2e 72 6f     root = tag.ro
15d0: 6f 74 2c 0a 20 20 20 20 20 20 62 75 74 74 6f 6e  ot,.      button
15e0: 20 3d 20 72 6f 6f 74 2e 67 65 74 45 6c 65 6d 65   = root.getEleme
15f0: 6e 74 73 42 79 54 61 67 4e 61 6d 65 28 27 62 75  ntsByTagName('bu
1600: 74 74 6f 6e 27 29 5b 30 5d 2c 0a 20 20 20 20 20  tton')[0],.     
1610: 20 63 68 69 6c 64 72 65 6e 2c 0a 20 20 20 20 20   children,.     
1620: 20 69 74 65 6d 73 43 6f 75 6e 74 20 3d 20 35 0a   itemsCount = 5.
1630: 0a 20 20 20 20 74 61 67 2e 69 74 65 6d 73 20 3d  .    tag.items =
1640: 20 5b 5d 0a 20 20 20 20 74 61 67 2e 72 65 6d 6f   [].    tag.remo
1650: 76 65 73 20 3d 20 5b 5d 0a 0a 20 20 20 20 77 68  ves = []..    wh
1660: 69 6c 65 20 28 69 74 65 6d 73 43 6f 75 6e 74 2d  ile (itemsCount-
1670: 2d 29 20 7b 0a 20 20 20 20 20 20 74 61 67 2e 72  -) {.      tag.r
1680: 65 6d 6f 76 65 73 2e 70 75 73 68 28 7b 0a 20 20  emoves.push({.  
1690: 20 20 20 20 20 20 76 61 6c 75 65 3a 20 27 72 65        value: 're
16a0: 6d 6f 76 65 20 69 74 65 6d 20 23 27 20 2b 20 74  move item #' + t
16b0: 61 67 2e 69 74 65 6d 73 2e 6c 65 6e 67 74 68 0a  ag.items.length.
16c0: 20 20 20 20 20 20 7d 29 0a 20 20 20 20 20 20 74        }).      t
16d0: 61 67 2e 69 74 65 6d 73 2e 70 75 73 68 28 7b 0a  ag.items.push({.
16e0: 20 20 20 20 20 20 20 20 76 61 6c 75 65 3a 20 27          value: '
16f0: 69 74 65 6d 20 23 27 20 2b 20 74 61 67 2e 69 74  item #' + tag.it
1700: 65 6d 73 2e 6c 65 6e 67 74 68 0a 20 20 20 20 20  ems.length.     
1710: 20 7d 29 0a 20 20 20 20 7d 0a 20 20 20 20 74 61   }).    }.    ta
1720: 67 2e 75 70 64 61 74 65 28 29 0a 0a 20 20 20 20  g.update()..    
1730: 2f 2f 20 72 65 6d 6f 76 65 20 74 68 65 20 69 74  // remove the it
1740: 65 6d 73 20 62 65 69 6e 67 20 73 75 72 65 20 74  ems being sure t
1750: 68 61 74 20 69 74 65 6d 20 70 61 73 73 65 64 20  hat item passed 
1760: 69 73 20 74 68 65 20 63 6f 72 72 65 63 74 20 6f  is the correct o
1770: 6e 65 0a 20 20 20 20 66 6f 72 20 28 76 61 72 20  ne.    for (var 
1780: 69 20 3d 20 30 3b 20 69 20 3c 20 74 61 67 2e 69  i = 0; i < tag.i
1790: 74 65 6d 73 2e 6c 65 6e 67 74 68 3b 20 69 2b 2b  tems.length; i++
17a0: 29 20 7b 0a 20 20 20 20 20 20 76 61 72 20 63 75  ) {.      var cu
17b0: 72 49 74 65 6d 20 3d 20 74 61 67 2e 72 65 6d 6f  rItem = tag.remo
17c0: 76 65 73 5b 30 5d 2c 0a 20 20 20 20 20 20 20 20  ves[0],.        
17d0: 65 76 20 3d 20 6e 65 77 20 43 75 73 74 6f 6d 45  ev = new CustomE
17e0: 76 65 6e 74 28 27 63 6c 69 63 6b 27 29 2c 0a 20  vent('click'),. 
17f0: 20 20 20 20 20 20 20 65 6c 20 3d 20 72 6f 6f 74         el = root
1800: 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61  .getElementsByTa
1810: 67 4e 61 6d 65 28 27 64 74 27 29 5b 30 5d 0a 0a  gName('dt')[0]..
1820: 20 20 20 20 20 20 65 6c 2e 64 69 73 70 61 74 63        el.dispatc
1830: 68 45 76 65 6e 74 28 65 76 29 0a 20 20 20 20 20  hEvent(ev).     
1840: 20 65 78 70 65 63 74 28 63 75 72 49 74 65 6d 29   expect(curItem)
1850: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 65 76 2e  .to.be.equal(ev.
1860: 69 74 65 6d 29 0a 20 20 20 20 7d 0a 0a 20 20 20  item).    }..   
1870: 20 63 68 69 6c 64 72 65 6e 20 3d 20 72 6f 6f 74   children = root
1880: 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61  .getElementsByTa
1890: 67 4e 61 6d 65 28 27 6c 69 27 29 0a 20 20 20 20  gName('li').    
18a0: 41 72 72 61 79 2e 70 72 6f 74 6f 74 79 70 65 2e  Array.prototype.
18b0: 66 6f 72 45 61 63 68 2e 63 61 6c 6c 28 63 68 69  forEach.call(chi
18c0: 6c 64 72 65 6e 2c 20 66 75 6e 63 74 69 6f 6e 28  ldren, function(
18d0: 63 68 69 6c 64 29 20 7b 0a 20 20 20 20 20 20 66  child) {.      f
18e0: 69 72 65 45 76 65 6e 74 28 63 68 69 6c 64 2c 20  ireEvent(child, 
18f0: 27 63 6c 69 63 6b 27 29 0a 20 20 20 20 7d 29 0a  'click').    }).
1900: 20 20 20 20 65 78 70 65 63 74 28 63 68 69 6c 64      expect(child
1910: 72 65 6e 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62  ren.length).to.b
1920: 65 2e 65 71 75 61 6c 28 35 29 0a 0a 20 20 20 20  e.equal(5)..    
1930: 2f 2f 20 6e 6f 20 75 70 64 61 74 65 20 69 73 20  // no update is 
1940: 72 65 71 75 69 72 65 64 20 68 65 72 65 0a 20 20  required here.  
1950: 20 20 66 69 72 65 45 76 65 6e 74 28 62 75 74 74    fireEvent(butt
1960: 6f 6e 2c 20 27 63 6c 69 63 6b 27 29 0a 20 20 20  on, 'click').   
1970: 20 63 68 69 6c 64 72 65 6e 20 3d 20 72 6f 6f 74   children = root
1980: 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61  .getElementsByTa
1990: 67 4e 61 6d 65 28 27 6c 69 27 29 0a 20 20 20 20  gName('li').    
19a0: 65 78 70 65 63 74 28 63 68 69 6c 64 72 65 6e 2e  expect(children.
19b0: 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71  length).to.be.eq
19c0: 75 61 6c 28 31 30 29 0a 0a 20 20 20 20 41 72 72  ual(10)..    Arr
19d0: 61 79 2e 70 72 6f 74 6f 74 79 70 65 2e 66 6f 72  ay.prototype.for
19e0: 45 61 63 68 2e 63 61 6c 6c 28 63 68 69 6c 64 72  Each.call(childr
19f0: 65 6e 2c 20 66 75 6e 63 74 69 6f 6e 28 63 68 69  en, function(chi
1a00: 6c 64 29 20 7b 0a 20 20 20 20 20 20 66 69 72 65  ld) {.      fire
1a10: 45 76 65 6e 74 28 63 68 69 6c 64 2c 20 27 63 6c  Event(child, 'cl
1a20: 69 63 6b 27 29 0a 20 20 20 20 7d 29 0a 0a 20 20  ick').    })..  
1a30: 20 20 65 78 70 65 63 74 28 6e 6f 72 6d 61 6c 69    expect(normali
1a40: 7a 65 48 54 4d 4c 28 72 6f 6f 74 2e 67 65 74 45  zeHTML(root.getE
1a50: 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65  lementsByTagName
1a60: 28 27 75 6c 27 29 5b 30 5d 2e 69 6e 6e 65 72 48  ('ul')[0].innerH
1a70: 54 4d 4c 29 29 2e 74 6f 2e 62 65 2e 65 71 75 61  TML)).to.be.equa
1a80: 6c 28 27 3c 6c 69 3e 30 20 69 74 65 6d 20 23 30  l('<li>0 item #0
1a90: 20 3c 2f 6c 69 3e 3c 6c 69 3e 31 20 69 74 65 6d   </li><li>1 item
1aa0: 20 23 31 20 3c 2f 6c 69 3e 3c 6c 69 3e 32 20 69   #1 </li><li>2 i
1ab0: 74 65 6d 20 23 32 20 3c 2f 6c 69 3e 3c 6c 69 3e  tem #2 </li><li>
1ac0: 33 20 69 74 65 6d 20 23 33 20 3c 2f 6c 69 3e 3c  3 item #3 </li><
1ad0: 6c 69 3e 34 20 69 74 65 6d 20 23 34 20 3c 2f 6c  li>4 item #4 </l
1ae0: 69 3e 3c 6c 69 3e 35 20 69 74 65 6d 20 23 35 20  i><li>5 item #5 
1af0: 3c 2f 6c 69 3e 3c 6c 69 3e 36 20 69 74 65 6d 20  </li><li>6 item 
1b00: 23 36 20 3c 2f 6c 69 3e 3c 6c 69 3e 37 20 69 74  #6 </li><li>7 it
1b10: 65 6d 20 23 37 20 3c 2f 6c 69 3e 3c 6c 69 3e 38  em #7 </li><li>8
1b20: 20 69 74 65 6d 20 23 38 20 3c 2f 6c 69 3e 3c 6c   item #8 </li><l
1b30: 69 3e 39 20 69 74 65 6d 20 23 39 20 3c 2f 6c 69  i>9 item #9 </li
1b40: 3e 27 29 0a 0a 20 20 20 20 74 61 67 2e 69 74 65  >')..    tag.ite
1b50: 6d 73 2e 72 65 76 65 72 73 65 28 29 0a 20 20 20  ms.reverse().   
1b60: 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a 20 20   tag.update().  
1b70: 20 20 63 68 69 6c 64 72 65 6e 20 3d 20 72 6f 6f    children = roo
1b80: 74 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54  t.getElementsByT
1b90: 61 67 4e 61 6d 65 28 27 6c 69 27 29 0a 20 20 20  agName('li').   
1ba0: 20 65 78 70 65 63 74 28 63 68 69 6c 64 72 65 6e   expect(children
1bb0: 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65  .length).to.be.e
1bc0: 71 75 61 6c 28 31 30 29 0a 20 20 20 20 41 72 72  qual(10).    Arr
1bd0: 61 79 2e 70 72 6f 74 6f 74 79 70 65 2e 66 6f 72  ay.prototype.for
1be0: 45 61 63 68 2e 63 61 6c 6c 28 63 68 69 6c 64 72  Each.call(childr
1bf0: 65 6e 2c 20 66 75 6e 63 74 69 6f 6e 28 63 68 69  en, function(chi
1c00: 6c 64 29 20 7b 0a 20 20 20 20 20 20 66 69 72 65  ld) {.      fire
1c10: 45 76 65 6e 74 28 63 68 69 6c 64 2c 20 27 63 6c  Event(child, 'cl
1c20: 69 63 6b 27 29 0a 20 20 20 20 7d 29 0a 0a 20 20  ick').    })..  
1c30: 20 20 65 78 70 65 63 74 28 6e 6f 72 6d 61 6c 69    expect(normali
1c40: 7a 65 48 54 4d 4c 28 72 6f 6f 74 2e 67 65 74 45  zeHTML(root.getE
1c50: 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65  lementsByTagName
1c60: 28 27 75 6c 27 29 5b 30 5d 2e 69 6e 6e 65 72 48  ('ul')[0].innerH
1c70: 54 4d 4c 29 29 2e 74 6f 2e 62 65 2e 65 71 75 61  TML)).to.be.equa
1c80: 6c 28 27 3c 6c 69 3e 30 20 69 74 65 6d 20 23 39  l('<li>0 item #9
1c90: 20 3c 2f 6c 69 3e 3c 6c 69 3e 31 20 69 74 65 6d   </li><li>1 item
1ca0: 20 23 38 20 3c 2f 6c 69 3e 3c 6c 69 3e 32 20 69   #8 </li><li>2 i
1cb0: 74 65 6d 20 23 37 20 3c 2f 6c 69 3e 3c 6c 69 3e  tem #7 </li><li>
1cc0: 33 20 69 74 65 6d 20 23 36 20 3c 2f 6c 69 3e 3c  3 item #6 </li><
1cd0: 6c 69 3e 34 20 69 74 65 6d 20 23 35 20 3c 2f 6c  li>4 item #5 </l
1ce0: 69 3e 3c 6c 69 3e 35 20 69 74 65 6d 20 23 34 20  i><li>5 item #4 
1cf0: 3c 2f 6c 69 3e 3c 6c 69 3e 36 20 69 74 65 6d 20  </li><li>6 item 
1d00: 23 33 20 3c 2f 6c 69 3e 3c 6c 69 3e 37 20 69 74  #3 </li><li>7 it
1d10: 65 6d 20 23 32 20 3c 2f 6c 69 3e 3c 6c 69 3e 38  em #2 </li><li>8
1d20: 20 69 74 65 6d 20 23 31 20 3c 2f 6c 69 3e 3c 6c   item #1 </li><l
1d30: 69 3e 39 20 69 74 65 6d 20 23 30 20 3c 2f 6c 69  i>9 item #0 </li
1d40: 3e 27 2e 74 72 69 6d 28 29 29 0a 0a 20 20 20 20  >'.trim())..    
1d50: 76 61 72 20 74 65 6d 70 49 74 65 6d 20 3d 20 74  var tempItem = t
1d60: 61 67 2e 69 74 65 6d 73 5b 31 5d 0a 20 20 20 20  ag.items[1].    
1d70: 74 61 67 2e 69 74 65 6d 73 5b 31 5d 20 3d 20 74  tag.items[1] = t
1d80: 61 67 2e 69 74 65 6d 73 5b 38 5d 0a 20 20 20 20  ag.items[8].    
1d90: 74 61 67 2e 69 74 65 6d 73 5b 38 5d 20 3d 20 74  tag.items[8] = t
1da0: 65 6d 70 49 74 65 6d 0a 20 20 20 20 74 61 67 2e  empItem.    tag.
1db0: 75 70 64 61 74 65 28 29 0a 0a 20 20 20 20 41 72  update()..    Ar
1dc0: 72 61 79 2e 70 72 6f 74 6f 74 79 70 65 2e 66 6f  ray.prototype.fo
1dd0: 72 45 61 63 68 2e 63 61 6c 6c 28 63 68 69 6c 64  rEach.call(child
1de0: 72 65 6e 2c 20 66 75 6e 63 74 69 6f 6e 28 63 68  ren, function(ch
1df0: 69 6c 64 29 20 7b 0a 20 20 20 20 20 20 66 69 72  ild) {.      fir
1e00: 65 45 76 65 6e 74 28 63 68 69 6c 64 2c 20 27 63  eEvent(child, 'c
1e10: 6c 69 63 6b 27 29 0a 20 20 20 20 7d 29 0a 0a 20  lick').    }).. 
1e20: 20 20 20 65 78 70 65 63 74 28 6e 6f 72 6d 61 6c     expect(normal
1e30: 69 7a 65 48 54 4d 4c 28 72 6f 6f 74 2e 67 65 74  izeHTML(root.get
1e40: 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d  ElementsByTagNam
1e50: 65 28 27 75 6c 27 29 5b 30 5d 2e 69 6e 6e 65 72  e('ul')[0].inner
1e60: 48 54 4d 4c 29 29 2e 74 6f 2e 62 65 2e 65 71 75  HTML)).to.be.equ
1e70: 61 6c 28 27 3c 6c 69 3e 30 20 69 74 65 6d 20 23  al('<li>0 item #
1e80: 39 20 3c 2f 6c 69 3e 3c 6c 69 3e 31 20 69 74 65  9 </li><li>1 ite
1e90: 6d 20 23 31 20 3c 2f 6c 69 3e 3c 6c 69 3e 32 20  m #1 </li><li>2 
1ea0: 69 74 65 6d 20 23 37 20 3c 2f 6c 69 3e 3c 6c 69  item #7 </li><li
1eb0: 3e 33 20 69 74 65 6d 20 23 36 20 3c 2f 6c 69 3e  >3 item #6 </li>
1ec0: 3c 6c 69 3e 34 20 69 74 65 6d 20 23 35 20 3c 2f  <li>4 item #5 </
1ed0: 6c 69 3e 3c 6c 69 3e 35 20 69 74 65 6d 20 23 34  li><li>5 item #4
1ee0: 20 3c 2f 6c 69 3e 3c 6c 69 3e 36 20 69 74 65 6d   </li><li>6 item
1ef0: 20 23 33 20 3c 2f 6c 69 3e 3c 6c 69 3e 37 20 69   #3 </li><li>7 i
1f00: 74 65 6d 20 23 32 20 3c 2f 6c 69 3e 3c 6c 69 3e  tem #2 </li><li>
1f10: 38 20 69 74 65 6d 20 23 38 20 3c 2f 6c 69 3e 3c  8 item #8 </li><
1f20: 6c 69 3e 39 20 69 74 65 6d 20 23 30 20 3c 2f 6c  li>9 item #0 </l
1f30: 69 3e 27 2e 74 72 69 6d 28 29 29 0a 0a 20 20 20  i>'.trim())..   
1f40: 20 74 61 67 2e 69 74 65 6d 73 20 3d 20 6e 75 6c   tag.items = nul
1f50: 6c 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74 65  l.    tag.update
1f60: 28 29 0a 20 20 20 20 65 78 70 65 63 74 28 72 6f  ().    expect(ro
1f70: 6f 74 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79  ot.getElementsBy
1f80: 54 61 67 4e 61 6d 65 28 27 6c 69 27 29 2e 6c 65  TagName('li').le
1f90: 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61  ngth).to.be.equa
1fa0: 6c 28 30 29 0a 0a 20 20 20 20 74 61 67 2e 75 6e  l(0)..    tag.un
1fb0: 6d 6f 75 6e 74 28 29 0a 0a 20 20 7d 29 0a 0a 20  mount()..  }).. 
1fc0: 20 69 74 28 27 74 68 65 20 65 76 65 6e 74 2e 69   it('the event.i
1fd0: 74 65 6d 20 70 72 6f 70 65 72 74 79 20 67 65 74  tem property get
1fe0: 73 20 68 61 6e 64 6c 65 64 20 63 6f 72 72 65 63  s handled correc
1ff0: 74 6c 79 20 61 6c 73 6f 20 69 6e 20 74 68 65 20  tly also in the 
2000: 6e 65 73 74 65 64 20 6c 6f 6f 70 73 27 2c 20 66  nested loops', f
2010: 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 0a 20 20 20  unction() {..   
2020: 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6c 6f   injectHTML('<lo
2030: 6f 70 2d 65 76 65 6e 74 73 3e 3c 2f 6c 6f 6f 70  op-events></loop
2040: 2d 65 76 65 6e 74 73 3e 27 29 0a 0a 20 20 20 20  -events>')..    
2050: 63 6f 6e 73 74 20 74 61 67 20 3d 20 72 69 6f 74  const tag = riot
2060: 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d 65 76 65  .mount('loop-eve
2070: 6e 74 73 27 2c 20 7b 0a 20 20 20 20 20 20 63 62  nts', {.      cb
2080: 3a 20 66 75 6e 63 74 69 6f 6e 28 65 2c 20 69 74  : function(e, it
2090: 65 6d 29 20 7b 0a 20 20 20 20 20 20 20 20 65 76  em) {.        ev
20a0: 65 6e 74 73 43 6f 75 6e 74 65 72 2b 2b 0a 20 20  entsCounter++.  
20b0: 20 20 20 20 20 20 69 66 20 28 65 2e 73 74 6f 70        if (e.stop
20c0: 50 72 6f 70 61 67 61 74 69 6f 6e 29 0a 20 20 20  Propagation).   
20d0: 20 20 20 20 20 20 20 65 2e 73 74 6f 70 50 72 6f         e.stopPro
20e0: 70 61 67 61 74 69 6f 6e 28 29 0a 20 20 20 20 20  pagation().     
20f0: 20 20 20 65 78 70 65 63 74 28 4a 53 4f 4e 2e 73     expect(JSON.s
2100: 74 72 69 6e 67 69 66 79 28 69 74 65 6d 29 29 2e  tringify(item)).
2110: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 4a 53 4f 4e  to.be.equal(JSON
2120: 2e 73 74 72 69 6e 67 69 66 79 28 74 65 73 74 49  .stringify(testI
2130: 74 65 6d 29 29 0a 20 20 20 20 20 20 7d 0a 20 20  tem)).      }.  
2140: 20 20 7d 29 5b 30 5d 0a 0a 20 20 20 20 6c 65 74    })[0]..    let
2150: 0a 20 20 20 20 20 20 65 76 65 6e 74 73 43 6f 75  .      eventsCou
2160: 6e 74 65 72 20 3d 20 30 2c 0a 20 20 20 20 20 20  nter = 0,.      
2170: 74 65 73 74 49 74 65 6d 0a 0a 20 20 20 20 2f 2f  testItem..    //
2180: 20 31 73 74 20 74 65 73 74 0a 20 20 20 20 74 65   1st test.    te
2190: 73 74 49 74 65 6d 20 3d 20 7b 20 6f 75 74 65 72  stItem = { outer
21a0: 43 6f 75 6e 74 3a 20 27 6f 75 74 27 2c 20 6f 75  Count: 'out', ou
21b0: 74 65 72 49 3a 20 30 20 7d 0a 20 20 20 20 66 69  terI: 0 }.    fi
21c0: 72 65 45 76 65 6e 74 28 74 61 67 2e 72 6f 6f 74  reEvent(tag.root
21d0: 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61  .getElementsByTa
21e0: 67 4e 61 6d 65 28 27 69 6e 6e 65 72 2d 6c 6f 6f  gName('inner-loo
21f0: 70 2d 65 76 65 6e 74 73 27 29 5b 30 5d 2c 20 27  p-events')[0], '
2200: 63 6c 69 63 6b 27 29 0a 20 20 20 20 2f 2f 20 32  click').    // 2
2210: 6e 64 20 74 65 73 74 20 69 6e 6e 65 72 20 63 6f  nd test inner co
2220: 6e 74 65 6e 74 73 0a 20 20 20 20 74 65 73 74 49  ntents.    testI
2230: 74 65 6d 20 3d 20 7b 20 69 6e 6e 65 72 43 6f 75  tem = { innerCou
2240: 6e 74 3a 20 27 69 6e 27 2c 20 69 6e 6e 65 72 49  nt: 'in', innerI
2250: 3a 20 30 20 7d 0a 20 20 20 20 66 69 72 65 45 76  : 0 }.    fireEv
2260: 65 6e 74 28 74 61 67 2e 72 6f 6f 74 2e 67 65 74  ent(tag.root.get
2270: 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d  ElementsByTagNam
2280: 65 28 27 62 75 74 74 6f 6e 27 29 5b 31 5d 2c 20  e('button')[1], 
2290: 27 63 6c 69 63 6b 27 29 0a 20 20 20 20 66 69 72  'click').    fir
22a0: 65 45 76 65 6e 74 28 74 61 67 2e 72 6f 6f 74 2e  eEvent(tag.root.
22b0: 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61 67  getElementsByTag
22c0: 4e 61 6d 65 28 27 6c 69 27 29 5b 30 5d 2c 20 27  Name('li')[0], '
22d0: 63 6c 69 63 6b 27 29 0a 0a 20 20 20 20 65 78 70  click')..    exp
22e0: 65 63 74 28 65 76 65 6e 74 73 43 6f 75 6e 74 65  ect(eventsCounte
22f0: 72 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 33  r).to.be.equal(3
2300: 29 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75  )..    tag.unmou
2310: 6e 74 28 29 0a 0a 20 20 7d 29 0a 0a 20 20 69 74  nt()..  })..  it
2320: 28 27 63 61 6e 20 6c 6f 6f 70 20 61 6c 73 6f 20  ('can loop also 
2330: 63 6f 6c 6c 65 63 74 69 6f 6e 73 20 69 6e 63 6c  collections incl
2340: 75 64 69 6e 67 20 6e 75 6c 6c 20 69 74 65 6d 73  uding null items
2350: 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a  ', function() {.
2360: 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28  .    injectHTML(
2370: 27 3c 6c 6f 6f 70 2d 6e 75 6c 6c 2d 69 74 65 6d  '<loop-null-item
2380: 73 3e 3c 2f 6c 6f 6f 70 2d 6e 75 6c 6c 2d 69 74  s></loop-null-it
2390: 65 6d 73 3e 27 29 0a 0a 20 20 20 20 63 6f 6e 73  ems>')..    cons
23a0: 74 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75  t tag = riot.mou
23b0: 6e 74 28 27 6c 6f 6f 70 2d 6e 75 6c 6c 2d 69 74  nt('loop-null-it
23c0: 65 6d 73 27 29 5b 30 5d 0a 20 20 20 20 65 78 70  ems')[0].    exp
23d0: 65 63 74 28 24 24 28 27 6c 69 27 2c 20 74 61 67  ect($$('li', tag
23e0: 2e 72 6f 6f 74 29 2e 6c 65 6e 67 74 68 29 2e 74  .root).length).t
23f0: 6f 2e 62 65 2e 65 71 75 61 6c 28 37 29 0a 20 20  o.be.equal(7).  
2400: 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a    tag.unmount().
2410: 20 20 7d 29 0a 0a 20 20 69 74 28 27 65 61 63 68    })..  it('each
2420: 20 6c 6f 6f 70 20 63 72 65 61 74 65 73 20 63 6f   loop creates co
2430: 72 72 65 63 74 6c 79 20 61 20 6e 65 77 20 63 6f  rrectly a new co
2440: 6e 74 65 78 74 27 2c 20 66 75 6e 63 74 69 6f 6e  ntext', function
2450: 28 29 20 7b 0a 0a 20 20 20 20 69 6e 6a 65 63 74  () {..    inject
2460: 48 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 63 68 69 6c  HTML('<loop-chil
2470: 64 3e 3c 2f 6c 6f 6f 70 2d 63 68 69 6c 64 3e 27  d></loop-child>'
2480: 29 0a 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67  )..    const tag
2490: 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c   = riot.mount('l
24a0: 6f 6f 70 2d 63 68 69 6c 64 27 29 5b 30 5d 2c 0a  oop-child')[0],.
24b0: 20 20 20 20 20 20 72 6f 6f 74 20 3d 20 74 61 67        root = tag
24c0: 2e 72 6f 6f 74 2c 0a 20 20 20 20 20 20 63 68 69  .root,.      chi
24d0: 6c 64 72 65 6e 20 3d 20 72 6f 6f 74 2e 67 65 74  ldren = root.get
24e0: 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d  ElementsByTagNam
24f0: 65 28 27 6c 6f 6f 70 65 64 2d 63 68 69 6c 64 27  e('looped-child'
2500: 29 0a 0a 20 20 20 20 65 78 70 65 63 74 28 63 68  )..    expect(ch
2510: 69 6c 64 72 65 6e 2e 6c 65 6e 67 74 68 29 2e 74  ildren.length).t
2520: 6f 2e 62 65 2e 65 71 75 61 6c 28 32 29 0a 20 20  o.be.equal(2).  
2530: 20 20 65 78 70 65 63 74 28 74 61 67 2e 74 61 67    expect(tag.tag
2540: 73 5b 27 6c 6f 6f 70 65 64 2d 63 68 69 6c 64 27  s['looped-child'
2550: 5d 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e  ].length).to.be.
2560: 65 71 75 61 6c 28 32 29 0a 20 20 20 20 65 78 70  equal(2).    exp
2570: 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f  ect(tag.tags['lo
2580: 6f 70 65 64 2d 63 68 69 6c 64 27 5d 5b 30 5d 2e  oped-child'][0].
2590: 68 69 74 29 2e 74 6f 2e 62 65 2e 61 28 27 66 75  hit).to.be.a('fu
25a0: 6e 63 74 69 6f 6e 27 29 0a 20 20 20 20 65 78 70  nction').    exp
25b0: 65 63 74 28 6e 6f 72 6d 61 6c 69 7a 65 48 54 4d  ect(normalizeHTM
25c0: 4c 28 63 68 69 6c 64 72 65 6e 5b 30 5d 2e 69 6e  L(children[0].in
25d0: 6e 65 72 48 54 4d 4c 29 29 2e 74 6f 2e 62 65 2e  nerHTML)).to.be.
25e0: 65 71 75 61 6c 28 27 3c 68 33 3e 6f 6e 65 3c 2f  equal('<h3>one</
25f0: 68 33 3e 3c 62 75 74 74 6f 6e 3e 6f 6e 65 3c 2f  h3><button>one</
2600: 62 75 74 74 6f 6e 3e 27 29 0a 20 20 20 20 65 78  button>').    ex
2610: 70 65 63 74 28 6e 6f 72 6d 61 6c 69 7a 65 48 54  pect(normalizeHT
2620: 4d 4c 28 63 68 69 6c 64 72 65 6e 5b 31 5d 2e 69  ML(children[1].i
2630: 6e 6e 65 72 48 54 4d 4c 29 29 2e 74 6f 2e 62 65  nnerHTML)).to.be
2640: 2e 65 71 75 61 6c 28 27 3c 68 33 3e 74 77 6f 3c  .equal('<h3>two<
2650: 2f 68 33 3e 3c 62 75 74 74 6f 6e 3e 74 77 6f 3c  /h3><button>two<
2660: 2f 62 75 74 74 6f 6e 3e 27 29 0a 0a 20 20 20 20  /button>')..    
2670: 74 61 67 2e 69 74 65 6d 73 20 3d 20 5b 20 7b 6e  tag.items = [ {n
2680: 61 6d 65 3a 20 27 6f 6e 65 27 7d 2c 20 7b 6e 61  ame: 'one'}, {na
2690: 6d 65 3a 20 27 74 77 6f 27 7d 2c 20 7b 6e 61 6d  me: 'two'}, {nam
26a0: 65 3a 20 27 74 68 72 65 65 27 7d 20 5d 0a 20 20  e: 'three'} ].  
26b0: 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a 20    tag.update(). 
26c0: 20 20 20 65 78 70 65 63 74 28 72 6f 6f 74 2e 67     expect(root.g
26d0: 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e  etElementsByTagN
26e0: 61 6d 65 28 27 6c 6f 6f 70 65 64 2d 63 68 69 6c  ame('looped-chil
26f0: 64 27 29 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62  d').length).to.b
2700: 65 2e 65 71 75 61 6c 28 33 29 0a 0a 20 20 20 20  e.equal(3)..    
2710: 65 78 70 65 63 74 28 74 61 67 2e 74 61 67 73 5b  expect(tag.tags[
2720: 27 6c 6f 6f 70 65 64 2d 63 68 69 6c 64 27 5d 5b  'looped-child'][
2730: 32 5d 2e 69 73 4d 6f 75 6e 74 65 64 29 2e 74 6f  2].isMounted).to
2740: 2e 62 65 2e 65 71 75 61 6c 28 74 72 75 65 29 0a  .be.equal(true).
2750: 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 74      expect(tag.t
2760: 61 67 73 5b 27 6c 6f 6f 70 65 64 2d 63 68 69 6c  ags['looped-chil
2770: 64 27 5d 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62  d'].length).to.b
2780: 65 2e 65 71 75 61 6c 28 33 29 0a 0a 20 20 20 20  e.equal(3)..    
2790: 65 78 70 65 63 74 28 72 6f 6f 74 2e 67 65 74 45  expect(root.getE
27a0: 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65  lementsByTagName
27b0: 28 27 6c 6f 6f 70 65 64 2d 63 68 69 6c 64 27 29  ('looped-child')
27c0: 5b 30 5d 2e 73 74 79 6c 65 2e 63 6f 6c 6f 72 29  [0].style.color)
27d0: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 72 65  .to.be.equal('re
27e0: 64 27 29 0a 20 20 20 20 66 69 72 65 45 76 65 6e  d').    fireEven
27f0: 74 28 72 6f 6f 74 2e 67 65 74 45 6c 65 6d 65 6e  t(root.getElemen
2800: 74 73 42 79 54 61 67 4e 61 6d 65 28 27 6c 6f 6f  tsByTagName('loo
2810: 70 65 64 2d 63 68 69 6c 64 27 29 5b 30 5d 2e 67  ped-child')[0].g
2820: 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e  etElementsByTagN
2830: 61 6d 65 28 27 62 75 74 74 6f 6e 27 29 5b 30 5d  ame('button')[0]
2840: 2c 20 27 63 6c 69 63 6b 27 29 0a 20 20 20 20 65  , 'click').    e
2850: 78 70 65 63 74 28 72 6f 6f 74 2e 67 65 74 45 6c  xpect(root.getEl
2860: 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65 28  ementsByTagName(
2870: 27 6c 6f 6f 70 65 64 2d 63 68 69 6c 64 27 29 5b  'looped-child')[
2880: 30 5d 2e 73 74 79 6c 65 2e 63 6f 6c 6f 72 29 2e  0].style.color).
2890: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 62 6c 75  to.be.equal('blu
28a0: 65 27 29 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d  e')..    tag.unm
28b0: 6f 75 6e 74 28 29 0a 0a 20 20 7d 29 0a 0a 0a 20  ount()..  })... 
28c0: 20 69 74 28 27 74 68 65 20 6c 6f 6f 70 20 63 68   it('the loop ch
28d0: 69 6c 64 72 65 6e 20 74 61 67 73 20 6d 75 73 74  ildren tags must
28e0: 20 66 69 72 65 20 74 68 65 20 5c 27 6d 6f 75 6e   fire the \'moun
28f0: 74 5c 27 20 65 76 65 6e 74 20 77 68 65 6e 20 74  t\' event when t
2900: 68 65 79 20 61 72 65 20 61 6c 72 65 61 64 79 20  hey are already 
2910: 69 6e 6a 65 63 74 65 6e 64 20 69 6e 74 6f 20 74  injectend into t
2920: 68 65 20 70 61 72 65 6e 74 27 2c 20 66 75 6e 63  he parent', func
2930: 74 69 6f 6e 28 64 6f 6e 65 29 20 7b 0a 0a 20 20  tion(done) {..  
2940: 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6c    injectHTML('<l
2950: 6f 6f 70 2d 63 68 69 6c 64 3e 3c 2f 6c 6f 6f 70  oop-child></loop
2960: 2d 63 68 69 6c 64 3e 27 29 0a 0a 20 20 20 20 63  -child>')..    c
2970: 6f 6e 73 74 20 74 61 67 20 3d 20 72 69 6f 74 2e  onst tag = riot.
2980: 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d 63 68 69 6c  mount('loop-chil
2990: 64 27 29 5b 30 5d 0a 0a 20 20 20 20 73 65 74 54  d')[0]..    setT
29a0: 69 6d 65 6f 75 74 28 66 75 6e 63 74 69 6f 6e 28  imeout(function(
29b0: 29 20 7b 0a 20 20 20 20 20 20 74 61 67 2e 74 61  ) {.      tag.ta
29c0: 67 73 5b 27 6c 6f 6f 70 65 64 2d 63 68 69 6c 64  gs['looped-child
29d0: 27 5d 2e 66 6f 72 45 61 63 68 28 66 75 6e 63 74  '].forEach(funct
29e0: 69 6f 6e 28 63 68 69 6c 64 29 20 7b 0a 20 20 20  ion(child) {.   
29f0: 20 20 20 20 20 65 78 70 65 63 74 28 63 68 69 6c       expect(chil
2a00: 64 2e 6d 6f 75 6e 74 57 69 64 74 68 29 2e 74 6f  d.mountWidth).to
2a10: 2e 62 65 2e 61 62 6f 76 65 28 30 29 0a 20 20 20  .be.above(0).   
2a20: 20 20 20 7d 29 0a 0a 20 20 20 20 20 20 74 61 67     })..      tag
2a30: 2e 63 68 69 6c 64 72 65 6e 4d 6f 75 6e 74 57 69  .childrenMountWi
2a40: 64 74 68 73 2e 66 6f 72 45 61 63 68 28 66 75 6e  dths.forEach(fun
2a50: 63 74 69 6f 6e 28 77 69 64 74 68 29 20 7b 0a 20  ction(width) {. 
2a60: 20 20 20 20 20 20 20 65 78 70 65 63 74 28 77 69         expect(wi
2a70: 64 74 68 29 2e 74 6f 2e 62 65 2e 61 62 6f 76 65  dth).to.be.above
2a80: 28 30 29 0a 20 20 20 20 20 20 7d 29 0a 0a 20 20  (0).      })..  
2a90: 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28      tag.unmount(
2aa0: 29 0a 0a 20 20 20 20 20 20 64 6f 6e 65 28 29 0a  )..      done().
2ab0: 20 20 20 20 7d 2c 20 31 30 30 29 0a 0a 20 20 7d      }, 100)..  }
2ac0: 29 0a 0a 20 20 69 74 28 27 74 68 65 20 60 61 72  )..  it('the `ar
2ad0: 72 61 79 2e 75 6e 73 68 69 66 74 60 20 6d 65 74  ray.unshift` met
2ae0: 68 6f 64 20 64 6f 65 73 20 6e 6f 74 20 62 72 65  hod does not bre
2af0: 61 6b 20 74 68 65 20 6c 6f 6f 70 27 2c 20 66 75  ak the loop', fu
2b00: 6e 63 74 69 6f 6e 28 29 20 7b 0a 0a 20 20 20 20  nction() {..    
2b10: 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6c 6f 6f  injectHTML('<loo
2b20: 70 2d 75 6e 73 68 69 66 74 3e 3c 2f 6c 6f 6f 70  p-unshift></loop
2b30: 2d 75 6e 73 68 69 66 74 3e 27 29 0a 0a 20 20 20  -unshift>')..   
2b40: 20 63 6f 6e 73 74 20 74 61 67 20 3d 20 72 69 6f   const tag = rio
2b50: 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d 75 6e  t.mount('loop-un
2b60: 73 68 69 66 74 27 29 5b 30 5d 0a 0a 20 20 20 20  shift')[0]..    
2b70: 65 78 70 65 63 74 28 74 61 67 2e 74 61 67 73 5b  expect(tag.tags[
2b80: 27 6c 6f 6f 70 2d 75 6e 73 68 69 66 74 2d 69 74  'loop-unshift-it
2b90: 65 6d 27 5d 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e  em'].length).to.
2ba0: 62 65 2e 65 71 75 61 6c 28 32 29 0a 20 20 20 20  be.equal(2).    
2bb0: 65 78 70 65 63 74 28 6e 6f 72 6d 61 6c 69 7a 65  expect(normalize
2bc0: 48 54 4d 4c 28 74 61 67 2e 72 6f 6f 74 2e 67 65  HTML(tag.root.ge
2bd0: 74 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61  tElementsByTagNa
2be0: 6d 65 28 27 6c 6f 6f 70 2d 75 6e 73 68 69 66 74  me('loop-unshift
2bf0: 2d 69 74 65 6d 27 29 5b 30 5d 2e 69 6e 6e 65 72  -item')[0].inner
2c00: 48 54 4d 4c 29 29 2e 74 6f 2e 62 65 2e 65 71 75  HTML)).to.be.equ
2c10: 61 6c 28 27 3c 70 3e 77 6f 6f 3c 2f 70 3e 27 29  al('<p>woo</p>')
2c20: 0a 20 20 20 20 74 61 67 2e 69 74 65 6d 73 2e 75  .    tag.items.u
2c30: 6e 73 68 69 66 74 28 7b 20 6e 61 6d 65 3a 20 27  nshift({ name: '
2c40: 62 61 7a 27 20 7d 29 0a 20 20 20 20 74 61 67 2e  baz' }).    tag.
2c50: 75 70 64 61 74 65 28 29 0a 20 20 20 20 65 78 70  update().    exp
2c60: 65 63 74 28 6e 6f 72 6d 61 6c 69 7a 65 48 54 4d  ect(normalizeHTM
2c70: 4c 28 74 61 67 2e 72 6f 6f 74 2e 67 65 74 45 6c  L(tag.root.getEl
2c80: 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65 28  ementsByTagName(
2c90: 27 6c 6f 6f 70 2d 75 6e 73 68 69 66 74 2d 69 74  'loop-unshift-it
2ca0: 65 6d 27 29 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d  em')[0].innerHTM
2cb0: 4c 29 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  L)).to.be.equal(
2cc0: 27 3c 70 3e 62 61 7a 3c 2f 70 3e 27 29 0a 0a 20  '<p>baz</p>').. 
2cd0: 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29     tag.unmount()
2ce0: 0a 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 65 61  ..  })..  it('ea
2cf0: 63 68 20 6c 6f 6f 70 20 61 64 64 73 20 61 6e 64  ch loop adds and
2d00: 20 72 65 6d 6f 76 65 73 20 69 74 65 6d 73 20 69   removes items i
2d10: 6e 20 74 68 65 20 72 69 67 68 74 20 70 6f 73 69  n the right posi
2d20: 74 69 6f 6e 20 28 77 68 65 6e 20 6d 75 6c 74 69  tion (when multi
2d30: 70 6c 65 20 69 74 65 6d 73 20 73 68 61 72 65 20  ple items share 
2d40: 74 68 65 20 73 61 6d 65 20 68 74 6d 6c 29 27 2c  the same html)',
2d50: 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 0a 20   function() {.. 
2d60: 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c     injectHTML('<
2d70: 6c 6f 6f 70 2d 6d 61 6e 69 70 3e 3c 2f 6c 6f 6f  loop-manip></loo
2d80: 70 2d 6d 61 6e 69 70 3e 27 29 0a 0a 20 20 20 20  p-manip>')..    
2d90: 63 6f 6e 73 74 20 74 61 67 20 3d 20 72 69 6f 74  const tag = riot
2da0: 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d 6d 61 6e  .mount('loop-man
2db0: 69 70 27 29 5b 30 5d 2c 0a 20 20 20 20 20 20 72  ip')[0],.      r
2dc0: 6f 6f 74 20 3d 20 74 61 67 2e 72 6f 6f 74 0a 0a  oot = tag.root..
2dd0: 20 20 20 20 74 61 67 2e 74 6f 70 28 29 0a 20 20      tag.top().  
2de0: 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a 20    tag.update(). 
2df0: 20 20 20 74 61 67 2e 62 6f 74 74 6f 6d 28 29 0a     tag.bottom().
2e00: 20 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 29      tag.update()
2e10: 0a 20 20 20 20 74 61 67 2e 74 6f 70 28 29 0a 20  .    tag.top(). 
2e20: 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a     tag.update().
2e30: 20 20 20 20 74 61 67 2e 62 6f 74 74 6f 6d 28 29      tag.bottom()
2e40: 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74 65 28  .    tag.update(
2e50: 29 0a 0a 20 20 20 20 65 78 70 65 63 74 28 6e 6f  )..    expect(no
2e60: 72 6d 61 6c 69 7a 65 48 54 4d 4c 28 72 6f 6f 74  rmalizeHTML(root
2e70: 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61  .getElementsByTa
2e80: 67 4e 61 6d 65 28 27 75 6c 27 29 5b 30 5d 2e 69  gName('ul')[0].i
2e90: 6e 6e 65 72 48 54 4d 4c 29 29 2e 74 6f 2e 62 65  nnerHTML)).to.be
2ea0: 2e 65 71 75 61 6c 28 27 3c 6c 69 3e 31 30 30 20  .equal('<li>100 
2eb0: 3c 61 3e 72 65 6d 6f 76 65 3c 2f 61 3e 3c 2f 6c  <a>remove</a></l
2ec0: 69 3e 3c 6c 69 3e 31 30 30 20 3c 61 3e 72 65 6d  i><li>100 <a>rem
2ed0: 6f 76 65 3c 2f 61 3e 3c 2f 6c 69 3e 3c 6c 69 3e  ove</a></li><li>
2ee0: 30 20 3c 61 3e 72 65 6d 6f 76 65 3c 2f 61 3e 3c  0 <a>remove</a><
2ef0: 2f 6c 69 3e 3c 6c 69 3e 31 20 3c 61 3e 72 65 6d  /li><li>1 <a>rem
2f00: 6f 76 65 3c 2f 61 3e 3c 2f 6c 69 3e 3c 6c 69 3e  ove</a></li><li>
2f10: 32 20 3c 61 3e 72 65 6d 6f 76 65 3c 2f 61 3e 3c  2 <a>remove</a><
2f20: 2f 6c 69 3e 3c 6c 69 3e 33 20 3c 61 3e 72 65 6d  /li><li>3 <a>rem
2f30: 6f 76 65 3c 2f 61 3e 3c 2f 6c 69 3e 3c 6c 69 3e  ove</a></li><li>
2f40: 34 20 3c 61 3e 72 65 6d 6f 76 65 3c 2f 61 3e 3c  4 <a>remove</a><
2f50: 2f 6c 69 3e 3c 6c 69 3e 35 20 3c 61 3e 72 65 6d  /li><li>5 <a>rem
2f60: 6f 76 65 3c 2f 61 3e 3c 2f 6c 69 3e 3c 6c 69 3e  ove</a></li><li>
2f70: 31 30 30 20 3c 61 3e 72 65 6d 6f 76 65 3c 2f 61  100 <a>remove</a
2f80: 3e 3c 2f 6c 69 3e 3c 6c 69 3e 31 30 30 20 3c 61  ></li><li>100 <a
2f90: 3e 72 65 6d 6f 76 65 3c 2f 61 3e 3c 2f 6c 69 3e  >remove</a></li>
2fa0: 27 2e 74 72 69 6d 28 29 29 0a 0a 20 20 20 20 74  '.trim())..    t
2fb0: 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 0a 20 20  ag.unmount()..  
2fc0: 7d 29 0a 0a 0a 20 20 69 74 28 27 74 61 67 73 20  })...  it('tags 
2fd0: 69 6e 20 64 69 66 66 65 72 65 6e 74 20 65 61 63  in different eac
2fe0: 68 20 6c 6f 6f 70 73 20 64 6f 6e 74 20 63 6f 6c  h loops dont col
2ff0: 6c 69 64 65 27 2c 20 66 75 6e 63 74 69 6f 6e 28  lide', function(
3000: 29 20 7b 0a 0a 20 20 20 20 69 6e 6a 65 63 74 48  ) {..    injectH
3010: 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 63 6f 6d 62 6f  TML('<loop-combo
3020: 3e 3c 2f 6c 6f 6f 70 2d 63 6f 6d 62 6f 3e 27 29  ></loop-combo>')
3030: 0a 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20  ..    const tag 
3040: 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f  = riot.mount('lo
3050: 6f 70 2d 63 6f 6d 62 6f 27 29 5b 30 5d 0a 0a 20  op-combo')[0].. 
3060: 20 20 20 65 78 70 65 63 74 28 6e 6f 72 6d 61 6c     expect(normal
3070: 69 7a 65 48 54 4d 4c 28 74 61 67 2e 72 6f 6f 74  izeHTML(tag.root
3080: 2e 69 6e 6e 65 72 48 54 4d 4c 29 29 0a 20 20 20  .innerHTML)).   
3090: 20 20 20 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28     .to.be.equal(
30a0: 27 3c 6c 63 69 20 78 3d 22 61 22 3e 3c 2f 6c 63  '<lci x="a"></lc
30b0: 69 3e 3c 64 69 76 3e 3c 6c 63 69 20 78 3d 22 79  i><div><lci x="y
30c0: 22 3e 3c 2f 6c 63 69 3e 3c 2f 64 69 76 3e 27 29  "></lci></div>')
30d0: 0a 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74 65  ..    tag.update
30e0: 28 7b 62 3a 20 5b 27 7a 27 5d 7d 29 0a 0a 20 20  ({b: ['z']})..  
30f0: 20 20 65 78 70 65 63 74 28 6e 6f 72 6d 61 6c 69    expect(normali
3100: 7a 65 48 54 4d 4c 28 74 61 67 2e 72 6f 6f 74 2e  zeHTML(tag.root.
3110: 69 6e 6e 65 72 48 54 4d 4c 29 29 0a 20 20 20 20  innerHTML)).    
3120: 20 20 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27    .to.be.equal('
3130: 3c 6c 63 69 20 78 3d 22 61 22 3e 3c 2f 6c 63 69  <lci x="a"></lci
3140: 3e 3c 64 69 76 3e 3c 6c 63 69 20 78 3d 22 7a 22  ><div><lci x="z"
3150: 3e 3c 2f 6c 63 69 3e 3c 2f 64 69 76 3e 27 29 0a  ></lci></div>').
3160: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
3170: 28 29 0a 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27  ()..  })..  it('
3180: 69 74 65 72 61 74 65 20 6f 76 65 72 20 61 6e 20  iterate over an 
3190: 6f 62 6a 65 63 74 2c 20 74 68 65 6e 20 6d 6f 64  object, then mod
31a0: 69 66 79 20 74 68 65 20 70 72 6f 70 65 72 74 79  ify the property
31b0: 20 61 6e 64 20 75 70 64 61 74 65 20 69 74 73 65   and update itse
31c0: 6c 66 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20  lf', function() 
31d0: 7b 0a 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d  {..    injectHTM
31e0: 4c 28 27 3c 6c 6f 6f 70 2d 6f 62 6a 65 63 74 3e  L('<loop-object>
31f0: 3c 2f 6c 6f 6f 70 2d 6f 62 6a 65 63 74 3e 27 29  </loop-object>')
3200: 0a 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20  ..    const tag 
3210: 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f  = riot.mount('lo
3220: 6f 70 2d 6f 62 6a 65 63 74 27 29 5b 30 5d 0a 20  op-object')[0]. 
3230: 20 20 20 76 61 72 20 72 6f 6f 74 20 3d 20 74 61     var root = ta
3240: 67 2e 72 6f 6f 74 0a 0a 20 20 20 20 65 78 70 65  g.root..    expe
3250: 63 74 28 6e 6f 72 6d 61 6c 69 7a 65 48 54 4d 4c  ct(normalizeHTML
3260: 28 72 6f 6f 74 2e 67 65 74 45 6c 65 6d 65 6e 74  (root.getElement
3270: 73 42 79 54 61 67 4e 61 6d 65 28 27 64 69 76 27  sByTagName('div'
3280: 29 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29 29  )[0].innerHTML))
3290: 0a 20 20 20 20 20 20 2e 74 6f 2e 62 65 2e 65 71  .      .to.be.eq
32a0: 75 61 6c 28 27 3c 70 3e 7a 65 72 6f 20 3d 20 30  ual('<p>zero = 0
32b0: 3c 2f 70 3e 3c 70 3e 6f 6e 65 20 3d 20 31 3c 2f  </p><p>one = 1</
32c0: 70 3e 3c 70 3e 74 77 6f 20 3d 20 32 3c 2f 70 3e  p><p>two = 2</p>
32d0: 3c 70 3e 74 68 72 65 65 20 3d 20 33 3c 2f 70 3e  <p>three = 3</p>
32e0: 27 29 0a 0a 20 20 20 20 66 6f 72 20 28 76 61 72  ')..    for (var
32f0: 20 6b 65 79 20 69 6e 20 74 61 67 2e 6f 62 6a 29   key in tag.obj)
3300: 20 7b 20 2f 2f 20 65 73 6c 69 6e 74 2d 64 69 73   { // eslint-dis
3310: 61 62 6c 65 2d 6c 69 6e 65 20 67 75 61 72 64 2d  able-line guard-
3320: 66 6f 72 2d 69 6e 0a 20 20 20 20 20 20 74 61 67  for-in.      tag
3330: 2e 6f 62 6a 5b 6b 65 79 5d 20 3d 20 74 61 67 2e  .obj[key] = tag.
3340: 6f 62 6a 5b 6b 65 79 5d 20 2a 20 32 0a 20 20 20  obj[key] * 2.   
3350: 20 7d 0a 0a 20 20 20 20 74 61 67 2e 75 70 64 61   }..    tag.upda
3360: 74 65 28 29 0a 20 20 20 20 65 78 70 65 63 74 28  te().    expect(
3370: 6e 6f 72 6d 61 6c 69 7a 65 48 54 4d 4c 28 72 6f  normalizeHTML(ro
3380: 6f 74 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79  ot.getElementsBy
3390: 54 61 67 4e 61 6d 65 28 27 64 69 76 27 29 5b 30  TagName('div')[0
33a0: 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29 29 0a 20 20  ].innerHTML)).  
33b0: 20 20 20 20 2e 74 6f 2e 62 65 2e 65 71 75 61 6c      .to.be.equal
33c0: 28 27 3c 70 3e 7a 65 72 6f 20 3d 20 30 3c 2f 70  ('<p>zero = 0</p
33d0: 3e 3c 70 3e 6f 6e 65 20 3d 20 32 3c 2f 70 3e 3c  ><p>one = 2</p><
33e0: 70 3e 74 77 6f 20 3d 20 34 3c 2f 70 3e 3c 70 3e  p>two = 4</p><p>
33f0: 74 68 72 65 65 20 3d 20 36 3c 2f 70 3e 27 29 0a  three = 6</p>').
3400: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
3410: 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 63  ().  })..  it('c
3420: 6f 6e 64 69 74 69 6f 6e 61 6c 20 64 69 72 65 63  onditional direc
3430: 74 69 76 65 73 20 77 6f 72 6b 20 61 6c 73 6f 20  tives work also 
3440: 6f 6e 20 6f 62 6a 65 63 74 20 6c 6f 6f 70 73 27  on object loops'
3450: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20  , function() {. 
3460: 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c     injectHTML('<
3470: 6c 6f 6f 70 2d 6f 62 6a 65 63 74 2d 63 6f 6e 64  loop-object-cond
3480: 69 74 69 6f 6e 61 6c 3e 3c 2f 6c 6f 6f 70 2d 6f  itional></loop-o
3490: 62 6a 65 63 74 2d 63 6f 6e 64 69 74 69 6f 6e 61  bject-conditiona
34a0: 6c 3e 27 29 0a 20 20 20 20 63 6f 6e 73 74 20 74  l>').    const t
34b0: 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28  ag = riot.mount(
34c0: 27 6c 6f 6f 70 2d 6f 62 6a 65 63 74 2d 63 6f 6e  'loop-object-con
34d0: 64 69 74 69 6f 6e 61 6c 27 29 5b 30 5d 0a 20 20  ditional')[0].  
34e0: 20 20 65 78 70 65 63 74 28 74 61 67 2e 72 65 66    expect(tag.ref
34f0: 73 2e 69 74 65 6d 73 29 2e 74 6f 2e 68 61 76 65  s.items).to.have
3500: 2e 6c 65 6e 67 74 68 28 34 29 0a 20 20 20 20 74  .length(4).    t
3510: 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d  ag.unmount().  }
3520: 29 0a 0a 20 20 69 74 28 27 74 68 65 20 6c 6f 6f  )..  it('the loo
3530: 70 20 63 68 69 6c 64 72 65 6e 20 69 6e 73 74 61  p children insta
3540: 6e 63 65 73 20 67 65 74 20 63 6f 72 72 65 63 74  nces get correct
3550: 6c 79 20 72 65 6d 6f 76 65 64 20 69 6e 20 74 68  ly removed in th
3560: 65 20 72 69 67 68 74 20 6f 72 64 65 72 27 2c 20  e right order', 
3570: 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 0a 20 20  function() {..  
3580: 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6c    injectHTML('<l
3590: 6f 6f 70 2d 69 64 73 3e 3c 2f 6c 6f 6f 70 2d 69  oop-ids></loop-i
35a0: 64 73 3e 27 29 0a 0a 20 20 20 20 63 6f 6e 73 74  ds>')..    const
35b0: 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e   tag = riot.moun
35c0: 74 28 27 6c 6f 6f 70 2d 69 64 73 27 29 5b 30 5d  t('loop-ids')[0]
35d0: 2c 0a 20 20 20 20 20 20 74 68 69 72 64 49 74 65  ,.      thirdIte
35e0: 6d 49 64 20 3d 20 74 61 67 2e 74 61 67 73 5b 27  mId = tag.tags['
35f0: 6c 6f 6f 70 2d 69 64 73 2d 69 74 65 6d 27 5d 5b  loop-ids-item'][
3600: 32 5d 2e 5f 72 69 6f 74 5f 69 64 0a 0a 20 20 20  2]._riot_id..   
3610: 20 74 61 67 2e 69 74 65 6d 73 2e 73 70 6c 69 63   tag.items.splic
3620: 65 28 30 2c 20 31 29 0a 20 20 20 20 74 61 67 2e  e(0, 1).    tag.
3630: 75 70 64 61 74 65 28 74 61 67 2e 74 61 67 73 5b  update(tag.tags[
3640: 27 6c 6f 6f 70 2d 69 64 73 2d 69 74 65 6d 27 5d  'loop-ids-item']
3650: 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67  ).    expect(tag
3660: 2e 69 74 65 6d 73 2e 6c 65 6e 67 74 68 29 2e 74  .items.length).t
3670: 6f 2e 62 65 2e 65 71 75 61 6c 28 32 29 0a 20 20  o.be.equal(2).  
3680: 20 20 2f 2f 20 74 68 65 20 73 65 63 6f 6e 64 20    // the second 
3690: 74 61 67 20 69 6e 73 74 61 6e 63 65 20 67 6f 74  tag instance got
36a0: 20 72 65 6d 6f 76 65 64 0a 20 20 20 20 2f 2f 20   removed.    // 
36b0: 73 6f 20 6e 6f 77 20 74 68 65 20 74 68 69 72 64  so now the third
36c0: 20 74 61 67 20 67 6f 74 20 6d 6f 76 65 64 20 74   tag got moved t
36d0: 6f 20 74 68 65 20 73 65 63 6f 6e 64 20 70 6f 73  o the second pos
36e0: 69 74 69 6f 6e 0a 20 20 20 20 65 78 70 65 63 74  ition.    expect
36f0: 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d  (tag.tags['loop-
3700: 69 64 73 2d 69 74 65 6d 27 5d 5b 31 5d 2e 5f 72  ids-item'][1]._r
3710: 69 6f 74 5f 69 64 29 2e 74 6f 2e 62 65 2e 65 71  iot_id).to.be.eq
3720: 75 61 6c 28 74 68 69 72 64 49 74 65 6d 49 64 29  ual(thirdItemId)
3730: 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e  ..    tag.unmoun
3740: 74 28 29 0a 0a 20 20 7d 29 0a 0a 20 20 69 74 28  t()..  })..  it(
3750: 27 65 61 63 68 20 74 61 67 20 69 6e 20 74 68 65  'each tag in the
3760: 20 22 74 61 67 73 22 20 70 72 6f 70 65 72 74 79   "tags" property
3770: 20 63 61 6e 20 62 65 20 6c 6f 6f 70 65 64 27 2c   can be looped',
3780: 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 0a 20   function() {.. 
3790: 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c     injectHTML('<
37a0: 6c 6f 6f 70 2d 73 69 6e 67 6c 65 2d 74 61 67 73  loop-single-tags
37b0: 3e 3c 2f 6c 6f 6f 70 2d 73 69 6e 67 6c 65 2d 74  ></loop-single-t
37c0: 61 67 73 3e 27 29 0a 0a 20 20 20 20 63 6f 6e 73  ags>')..    cons
37d0: 74 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75  t tag = riot.mou
37e0: 6e 74 28 27 6c 6f 6f 70 2d 73 69 6e 67 6c 65 2d  nt('loop-single-
37f0: 74 61 67 73 27 29 5b 30 5d 0a 0a 20 20 20 20 65  tags')[0]..    e
3800: 78 70 65 63 74 28 24 24 28 27 75 6c 20 6c 69 27  xpect($$('ul li'
3810: 2c 20 74 61 67 2e 72 6f 6f 74 29 2e 6c 65 6e 67  , tag.root).leng
3820: 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  th).to.be.equal(
3830: 34 29 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f  4)..    tag.unmo
3840: 75 6e 74 28 29 0a 0a 20 20 7d 29 0a 0a 20 20 69  unt()..  })..  i
3850: 74 28 27 6c 6f 6f 70 20 6f 70 74 69 6f 6e 20 74  t('loop option t
3860: 61 67 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20  ag', function() 
3870: 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c  {.    injectHTML
3880: 28 27 3c 6c 6f 6f 70 2d 6f 70 74 69 6f 6e 3e 3c  ('<loop-option><
3890: 2f 6c 6f 6f 70 2d 6f 70 74 69 6f 6e 3e 27 29 0a  /loop-option>').
38a0: 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d  .    const tag =
38b0: 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f   riot.mount('loo
38c0: 70 2d 6f 70 74 69 6f 6e 27 29 5b 30 5d 2c 0a 20  p-option')[0],. 
38d0: 20 20 20 20 20 72 6f 6f 74 20 3d 20 74 61 67 2e       root = tag.
38e0: 72 6f 6f 74 2c 0a 20 20 20 20 20 20 6f 70 74 69  root,.      opti
38f0: 6f 6e 73 20 3d 20 72 6f 6f 74 2e 67 65 74 45 6c  ons = root.getEl
3900: 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65 28  ementsByTagName(
3910: 27 73 65 6c 65 63 74 27 29 5b 30 5d 0a 0a 0a 20  'select')[0]... 
3920: 20 20 20 2f 2f 65 78 70 65 63 74 28 6f 70 74 69     //expect(opti
3930: 6f 6e 73 5b 30 5d 2e 73 65 6c 65 63 74 65 64 29  ons[0].selected)
3940: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 66 61 6c  .to.be.equal(fal
3950: 73 65 29 0a 20 20 20 20 65 78 70 65 63 74 28 6f  se).    expect(o
3960: 70 74 69 6f 6e 73 5b 31 5d 2e 73 65 6c 65 63 74  ptions[1].select
3970: 65 64 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  ed).to.be.equal(
3980: 74 72 75 65 29 0a 20 20 20 20 65 78 70 65 63 74  true).    expect
3990: 28 6f 70 74 69 6f 6e 73 5b 32 5d 2e 73 65 6c 65  (options[2].sele
39a0: 63 74 65 64 29 2e 74 6f 2e 62 65 2e 65 71 75 61  cted).to.be.equa
39b0: 6c 28 66 61 6c 73 65 29 0a 20 20 20 20 65 78 70  l(false).    exp
39c0: 65 63 74 28 6f 70 74 69 6f 6e 73 2e 73 65 6c 65  ect(options.sele
39d0: 63 74 65 64 49 6e 64 65 78 29 2e 74 6f 2e 62 65  ctedIndex).to.be
39e0: 2e 65 71 75 61 6c 28 31 29 0a 0a 20 20 20 20 74  .equal(1)..    t
39f0: 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 0a 20 20  ag.unmount()..  
3a00: 7d 29 0a 0a 20 20 69 74 28 27 74 68 65 20 72 65  })..  it('the re
3a10: 66 65 72 65 6e 63 65 64 20 6f 6e 20 61 20 73 65  ferenced on a se
3a20: 6c 65 63 74 20 74 61 67 20 67 65 74 73 27 2c 20  lect tag gets', 
3a30: 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 0a 20 20  function() {..  
3a40: 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6e    injectHTML('<n
3a50: 61 6d 65 64 2d 73 65 6c 65 63 74 3e 3c 2f 6e 61  amed-select></na
3a60: 6d 65 64 2d 73 65 6c 65 63 74 3e 27 29 0a 0a 20  med-select>').. 
3a70: 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d 20 72     const tag = r
3a80: 69 6f 74 2e 6d 6f 75 6e 74 28 27 6e 61 6d 65 64  iot.mount('named
3a90: 2d 73 65 6c 65 63 74 27 29 5b 30 5d 0a 0a 20 20  -select')[0]..  
3aa0: 20 20 65 78 70 65 63 74 28 74 61 67 2e 72 65 66    expect(tag.ref
3ab0: 73 2e 64 61 53 65 6c 65 63 74 29 2e 74 6f 2e 6e  s.daSelect).to.n
3ac0: 6f 74 2e 62 65 2e 65 71 75 61 6c 28 75 6e 64 65  ot.be.equal(unde
3ad0: 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70 65 63  fined).    expec
3ae0: 74 28 74 61 67 2e 72 65 66 73 2e 64 61 53 65 6c  t(tag.refs.daSel
3af0: 65 63 74 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62  ect.length).to.b
3b00: 65 2e 65 71 75 61 6c 28 32 29 0a 0a 20 20 20 20  e.equal(2)..    
3b10: 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20  tag.unmount().  
3b20: 7d 29 0a 0a 20 20 69 74 28 27 6c 6f 6f 70 20 6f  })..  it('loop o
3b30: 70 74 67 72 6f 75 70 20 74 61 67 27 2c 20 66 75  ptgroup tag', fu
3b40: 6e 63 74 69 6f 6e 28 29 20 7b 0a 0a 20 20 20 20  nction() {..    
3b50: 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6c 6f 6f  injectHTML('<loo
3b60: 70 2d 6f 70 74 67 72 6f 75 70 3e 3c 2f 6c 6f 6f  p-optgroup></loo
3b70: 70 2d 6f 70 74 67 72 6f 75 70 3e 27 29 0a 0a 20  p-optgroup>').. 
3b80: 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d 20 72     const tag = r
3b90: 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d  iot.mount('loop-
3ba0: 6f 70 74 67 72 6f 75 70 27 29 5b 30 5d 2c 0a 20  optgroup')[0],. 
3bb0: 20 20 20 20 20 72 6f 6f 74 20 3d 20 74 61 67 2e       root = tag.
3bc0: 72 6f 6f 74 2c 0a 20 20 20 20 20 20 73 65 6c 65  root,.      sele
3bd0: 63 74 20 3d 20 24 28 27 73 65 6c 65 63 74 27 2c  ct = $('select',
3be0: 20 72 6f 6f 74 29 0a 0a 20 20 20 20 65 78 70 65   root)..    expe
3bf0: 63 74 28 73 65 6c 65 63 74 2e 6f 70 74 69 6f 6e  ct(select.option
3c00: 73 5b 33 5d 2e 73 65 6c 65 63 74 65 64 29 2e 74  s[3].selected).t
3c10: 6f 2e 62 65 2e 65 71 75 61 6c 28 74 72 75 65 29  o.be.equal(true)
3c20: 0a 20 20 20 20 65 78 70 65 63 74 28 73 65 6c 65  .    expect(sele
3c30: 63 74 2e 6f 70 74 69 6f 6e 73 5b 30 5d 2e 76 61  ct.options[0].va
3c40: 6c 75 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  lue).to.be.equal
3c50: 28 27 31 27 29 0a 20 20 20 20 65 78 70 65 63 74  ('1').    expect
3c60: 28 73 65 6c 65 63 74 2e 6f 70 74 69 6f 6e 73 5b  (select.options[
3c70: 30 5d 2e 74 65 78 74 29 2e 74 6f 2e 62 65 2e 65  0].text).to.be.e
3c80: 71 75 61 6c 28 27 4f 70 74 69 6f 6e 20 31 2e 31  qual('Option 1.1
3c90: 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 73 65  ').    expect(se
3ca0: 6c 65 63 74 2e 6f 70 74 69 6f 6e 73 5b 31 5d 2e  lect.options[1].
3cb0: 74 65 78 74 29 2e 74 6f 2e 62 65 2e 65 71 75 61  text).to.be.equa
3cc0: 6c 28 27 4f 70 74 69 6f 6e 20 31 2e 32 27 29 0a  l('Option 1.2').
3cd0: 20 20 20 20 65 78 70 65 63 74 28 73 65 6c 65 63      expect(selec
3ce0: 74 2e 73 65 6c 65 63 74 65 64 49 6e 64 65 78 29  t.selectedIndex)
3cf0: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 33 29 0a  .to.be.equal(3).
3d00: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
3d10: 28 29 0a 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27  ()..  })..  it('
3d20: 6c 6f 6f 70 20 6f 70 74 67 72 6f 75 70 20 74 61  loop optgroup ta
3d30: 67 20 28 6f 75 74 65 72 20 6f 70 74 69 6f 6e 2c  g (outer option,
3d40: 20 6e 6f 20 63 6c 6f 73 69 6e 67 20 6f 70 74 69   no closing opti
3d50: 6f 6e 20 74 61 67 73 29 27 2c 20 66 75 6e 63 74  on tags)', funct
3d60: 69 6f 6e 28 29 20 7b 0a 0a 20 20 20 20 69 6e 6a  ion() {..    inj
3d70: 65 63 74 48 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 6f  ectHTML('<loop-o
3d80: 70 74 67 72 6f 75 70 32 3e 3c 2f 6c 6f 6f 70 2d  ptgroup2></loop-
3d90: 6f 70 74 67 72 6f 75 70 32 3e 27 29 0a 0a 20 20  optgroup2>')..  
3da0: 20 20 63 6f 6e 73 74 20 74 61 67 20 3d 20 72 69    const tag = ri
3db0: 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d 6f  ot.mount('loop-o
3dc0: 70 74 67 72 6f 75 70 32 27 29 5b 30 5d 2c 0a 20  ptgroup2')[0],. 
3dd0: 20 20 20 20 20 72 6f 6f 74 20 3d 20 74 61 67 2e       root = tag.
3de0: 72 6f 6f 74 2c 0a 20 20 20 20 20 20 73 65 6c 65  root,.      sele
3df0: 63 74 20 3d 20 24 28 27 73 65 6c 65 63 74 27 2c  ct = $('select',
3e00: 20 72 6f 6f 74 29 0a 0a 20 20 20 20 65 78 70 65   root)..    expe
3e10: 63 74 28 73 65 6c 65 63 74 2e 6f 70 74 69 6f 6e  ct(select.option
3e20: 73 5b 30 5d 2e 73 65 6c 65 63 74 65 64 29 2e 74  s[0].selected).t
3e30: 6f 2e 62 65 2e 65 71 75 61 6c 28 74 72 75 65 29  o.be.equal(true)
3e40: 0a 20 20 20 20 65 78 70 65 63 74 28 73 65 6c 65  .    expect(sele
3e50: 63 74 2e 6f 70 74 69 6f 6e 73 5b 34 5d 2e 64 69  ct.options[4].di
3e60: 73 61 62 6c 65 64 29 2e 74 6f 2e 62 65 2e 65 71  sabled).to.be.eq
3e70: 75 61 6c 28 74 72 75 65 29 0a 20 20 20 20 65 78  ual(true).    ex
3e80: 70 65 63 74 28 73 65 6c 65 63 74 2e 6f 70 74 69  pect(select.opti
3e90: 6f 6e 73 5b 31 5d 2e 76 61 6c 75 65 29 2e 74 6f  ons[1].value).to
3ea0: 2e 62 65 2e 65 71 75 61 6c 28 27 31 27 29 0a 20  .be.equal('1'). 
3eb0: 20 20 20 65 78 70 65 63 74 28 73 65 6c 65 63 74     expect(select
3ec0: 2e 6f 70 74 69 6f 6e 73 5b 30 5d 2e 74 65 78 74  .options[0].text
3ed0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 3c  ).to.be.equal('<
3ee0: 53 65 6c 65 63 74 20 4f 70 74 69 6f 6e 3e 27 29  Select Option>')
3ef0: 0a 20 20 20 20 65 78 70 65 63 74 28 73 65 6c 65  .    expect(sele
3f00: 63 74 2e 73 65 6c 65 63 74 65 64 49 6e 64 65 78  ct.selectedIndex
3f10: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 30 29  ).to.be.equal(0)
3f20: 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e  ..    tag.unmoun
3f30: 74 28 29 0a 0a 20 20 7d 29 0a 0a 20 20 69 74 28  t()..  })..  it(
3f40: 27 6c 6f 6f 70 20 74 72 20 74 61 62 6c 65 20 74  'loop tr table t
3f50: 61 67 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20  ag', function() 
3f60: 7b 0a 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d  {..    injectHTM
3f70: 4c 28 27 3c 74 61 62 6c 65 2d 64 61 74 61 3e 3c  L('<table-data><
3f80: 2f 74 61 62 6c 65 2d 64 61 74 61 3e 27 29 0a 0a  /table-data>')..
3f90: 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d 20      const tag = 
3fa0: 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 74 61 62 6c  riot.mount('tabl
3fb0: 65 2d 64 61 74 61 27 29 5b 30 5d 2c 0a 20 20 20  e-data')[0],.   
3fc0: 20 20 20 72 6f 6f 74 20 3d 20 74 61 67 2e 72 6f     root = tag.ro
3fd0: 6f 74 0a 0a 20 20 20 20 65 78 70 65 63 74 28 6e  ot..    expect(n
3fe0: 6f 72 6d 61 6c 69 7a 65 48 54 4d 4c 28 72 6f 6f  ormalizeHTML(roo
3ff0: 74 2e 69 6e 6e 65 72 48 54 4d 4c 29 29 2e 74 6f  t.innerHTML)).to
4000: 2e 6d 61 74 63 68 28 2f 3c 68 33 3e 43 65 6c 6c  .match(/<h3>Cell
4010: 73 3c 5c 2f 68 33 3e 3c 74 61 62 6c 65 20 62 6f  s<\/h3><table bo
4020: 72 64 65 72 3d 22 31 22 3e 3c 74 62 6f 64 79 3e  rder="1"><tbody>
4030: 3c 74 72 3e 3c 74 68 3e 4f 6e 65 3c 5c 2f 74 68  <tr><th>One<\/th
4040: 3e 3c 74 68 3e 54 77 6f 3c 5c 2f 74 68 3e 3c 74  ><th>Two<\/th><t
4050: 68 3e 54 68 72 65 65 3c 5c 2f 74 68 3e 3c 5c 2f  h>Three<\/th><\/
4060: 74 72 3e 3c 74 72 3e 3c 74 64 3e 4f 6e 65 3c 5c  tr><tr><td>One<\
4070: 2f 74 64 3e 3c 74 64 3e 54 77 6f 3c 5c 2f 74 64  /td><td>Two<\/td
4080: 3e 3c 74 64 3e 54 68 72 65 65 3c 5c 2f 74 64 3e  ><td>Three<\/td>
4090: 3c 5c 2f 74 72 3e 3c 5c 2f 74 62 6f 64 79 3e 3c  <\/tr><\/tbody><
40a0: 5c 2f 74 61 62 6c 65 3e 3c 68 33 3e 52 6f 77 73  \/table><h3>Rows
40b0: 3c 5c 2f 68 33 3e 3c 74 61 62 6c 65 20 62 6f 72  <\/h3><table bor
40c0: 64 65 72 3d 22 31 22 3e 3c 74 62 6f 64 79 3e 3c  der="1"><tbody><
40d0: 74 72 3e 3c 74 64 3e 4f 6e 65 3c 5c 2f 74 64 3e  tr><td>One<\/td>
40e0: 3c 74 64 3e 4f 6e 65 20 61 6e 6f 74 68 65 72 3c  <td>One another<
40f0: 5c 2f 74 64 3e 3c 5c 2f 74 72 3e 3c 74 72 3e 3c  \/td><\/tr><tr><
4100: 74 64 3e 54 77 6f 3c 5c 2f 74 64 3e 3c 74 64 3e  td>Two<\/td><td>
4110: 54 77 6f 20 61 6e 6f 74 68 65 72 3c 5c 2f 74 64  Two another<\/td
4120: 3e 3c 5c 2f 74 72 3e 3c 74 72 3e 3c 74 64 3e 54  ><\/tr><tr><td>T
4130: 68 72 65 65 3c 5c 2f 74 64 3e 3c 74 64 3e 54 68  hree<\/td><td>Th
4140: 72 65 65 20 61 6e 6f 74 68 65 72 3c 5c 2f 74 64  ree another<\/td
4150: 3e 3c 5c 2f 74 72 3e 3c 5c 2f 74 62 6f 64 79 3e  ><\/tr><\/tbody>
4160: 3c 5c 2f 74 61 62 6c 65 3e 2f 29 0a 0a 20 20 20  <\/table>/)..   
4170: 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 0a   tag.unmount()..
4180: 20 20 7d 29 0a 0a 20 20 69 74 28 27 6c 6f 6f 70    })..  it('loop
4190: 20 74 72 20 69 6e 20 74 61 62 6c 65 73 20 70 72   tr in tables pr
41a0: 65 73 65 72 76 69 6e 67 20 70 72 65 65 78 73 69  eserving preexsi
41b0: 73 74 69 6e 67 20 72 6f 77 73 27 2c 20 66 75 6e  sting rows', fun
41c0: 63 74 69 6f 6e 28 29 20 7b 0a 0a 20 20 20 20 69  ction() {..    i
41d0: 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 74 61 62 6c  njectHTML('<tabl
41e0: 65 2d 6c 6f 6f 70 2d 65 78 74 72 61 2d 72 6f 77  e-loop-extra-row
41f0: 3e 3c 2f 74 61 62 6c 65 2d 6c 6f 6f 70 2d 65 78  ></table-loop-ex
4200: 74 72 61 2d 72 6f 77 3e 27 29 0a 0a 20 20 20 20  tra-row>')..    
4210: 63 6f 6e 73 74 20 74 61 67 20 3d 20 72 69 6f 74  const tag = riot
4220: 2e 6d 6f 75 6e 74 28 27 74 61 62 6c 65 2d 6c 6f  .mount('table-lo
4230: 6f 70 2d 65 78 74 72 61 2d 72 6f 77 27 29 5b 30  op-extra-row')[0
4240: 5d 2c 0a 20 20 20 20 20 20 72 6f 6f 74 20 3d 20  ],.      root = 
4250: 74 61 67 2e 72 6f 6f 74 2c 0a 20 20 20 20 20 20  tag.root,.      
4260: 74 72 20 3d 20 24 24 28 27 74 61 62 6c 65 20 74  tr = $$('table t
4270: 72 27 2c 20 72 6f 6f 74 29 0a 0a 20 20 20 20 65  r', root)..    e
4280: 78 70 65 63 74 28 74 72 2e 6c 65 6e 67 74 68 29  xpect(tr.length)
4290: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 35 29 0a  .to.be.equal(5).
42a0: 20 20 20 20 65 78 70 65 63 74 28 6e 6f 72 6d 61      expect(norma
42b0: 6c 69 7a 65 48 54 4d 4c 28 74 72 5b 30 5d 2e 69  lizeHTML(tr[0].i
42c0: 6e 6e 65 72 48 54 4d 4c 29 29 2e 74 6f 2e 62 65  nnerHTML)).to.be
42d0: 2e 65 71 75 61 6c 28 27 3c 74 64 3e 45 78 74 72  .equal('<td>Extr
42e0: 61 3c 2f 74 64 3e 3c 74 64 3e 52 6f 77 31 3c 2f  a</td><td>Row1</
42f0: 74 64 3e 27 29 0a 20 20 20 20 65 78 70 65 63 74  td>').    expect
4300: 28 6e 6f 72 6d 61 6c 69 7a 65 48 54 4d 4c 28 74  (normalizeHTML(t
4310: 72 5b 34 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29 29  r[4].innerHTML))
4320: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 3c 74  .to.be.equal('<t
4330: 64 3e 45 78 74 72 61 3c 2f 74 64 3e 3c 74 64 3e  d>Extra</td><td>
4340: 52 6f 77 32 3c 2f 74 64 3e 27 29 0a 0a 20 20 20  Row2</td>')..   
4350: 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20   tag.unmount(). 
4360: 20 7d 29 0a 0a 20 20 69 74 28 27 6c 6f 6f 70 20   })..  it('loop 
4370: 72 65 6f 72 64 65 72 20 64 6f 6d 20 6e 6f 64 65  reorder dom node
4380: 73 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b  s', function() {
4390: 0a 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c  ..    injectHTML
43a0: 28 27 3c 6c 6f 6f 70 2d 72 65 6f 72 64 65 72 3e  ('<loop-reorder>
43b0: 3c 2f 6c 6f 6f 70 2d 72 65 6f 72 64 65 72 3e 27  </loop-reorder>'
43c0: 29 0a 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67  )..    const tag
43d0: 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c   = riot.mount('l
43e0: 6f 6f 70 2d 72 65 6f 72 64 65 72 27 29 5b 30 5d  oop-reorder')[0]
43f0: 0a 20 20 20 20 65 78 70 65 63 74 28 24 24 28 27  .    expect($$('
4400: 73 70 61 6e 27 2c 20 74 61 67 2e 72 6f 6f 74 29  span', tag.root)
4410: 5b 30 5d 2e 63 6c 61 73 73 4e 61 6d 65 29 2e 74  [0].className).t
4420: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 6e 72 2d 30  o.be.equal('nr-0
4430: 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 24 24  ').    expect($$
4440: 28 27 64 69 76 27 2c 20 74 61 67 2e 72 6f 6f 74  ('div', tag.root
4450: 29 5b 30 5d 2e 63 6c 61 73 73 4e 61 6d 65 29 2e  )[0].className).
4460: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 6e 72 2d  to.be.equal('nr-
4470: 30 27 29 0a 20 20 20 20 74 61 67 2e 69 74 65 6d  0').    tag.item
4480: 73 2e 72 65 76 65 72 73 65 28 29 0a 20 20 20 20  s.reverse().    
4490: 74 61 67 2e 75 70 64 61 74 65 28 29 0a 20 20 20  tag.update().   
44a0: 20 65 78 70 65 63 74 28 24 24 28 27 73 70 61 6e   expect($$('span
44b0: 27 2c 20 74 61 67 2e 72 6f 6f 74 29 5b 30 5d 2e  ', tag.root)[0].
44c0: 63 6c 61 73 73 4e 61 6d 65 29 2e 74 6f 2e 62 65  className).to.be
44d0: 2e 65 71 75 61 6c 28 27 6e 72 2d 35 27 29 0a 20  .equal('nr-5'). 
44e0: 20 20 20 65 78 70 65 63 74 28 24 24 28 27 64 69     expect($$('di
44f0: 76 27 2c 20 74 61 67 2e 72 6f 6f 74 29 5b 30 5d  v', tag.root)[0]
4500: 2e 63 6c 61 73 73 4e 61 6d 65 29 2e 74 6f 2e 62  .className).to.b
4510: 65 2e 65 71 75 61 6c 28 27 6e 72 2d 30 27 29 0a  e.equal('nr-0').
4520: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
4530: 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 74  ().  })..  it('t
4540: 61 67 73 20 70 72 6f 70 65 72 74 79 20 69 6e 20  ags property in 
4550: 6c 6f 6f 70 2c 20 76 61 72 79 69 6e 67 20 6c 65  loop, varying le
4560: 76 65 6c 73 20 6f 66 20 6e 65 73 74 69 6e 67 27  vels of nesting'
4570: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 0a  , function() {..
4580: 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 5b      injectHTML([
4590: 0a 20 20 20 20 20 20 27 3c 70 6c 6f 6f 70 2d 74  .      '<ploop-t
45a0: 61 67 3e 3c 2f 70 6c 6f 6f 70 2d 74 61 67 3e 27  ag></ploop-tag>'
45b0: 2c 0a 20 20 20 20 20 20 27 3c 70 6c 6f 6f 70 31  ,.      '<ploop1
45c0: 2d 74 61 67 3e 3c 2f 70 6c 6f 6f 70 31 2d 74 61  -tag></ploop1-ta
45d0: 67 3e 27 2c 0a 20 20 20 20 20 20 27 3c 70 6c 6f  g>',.      '<plo
45e0: 6f 70 32 2d 74 61 67 3e 3c 2f 70 6c 6f 6f 70 32  op2-tag></ploop2
45f0: 2d 74 61 67 3e 27 2c 0a 20 20 20 20 20 20 27 3c  -tag>',.      '<
4600: 70 6c 6f 6f 70 33 2d 74 61 67 3e 3c 2f 70 6c 6f  ploop3-tag></plo
4610: 6f 70 33 2d 74 61 67 3e 27 0a 20 20 20 20 5d 29  op3-tag>'.    ])
4620: 0a 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20  ..    const tag 
4630: 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 70 6c  = riot.mount('pl
4640: 6f 6f 70 2d 74 61 67 2c 20 70 6c 6f 6f 70 31 2d  oop-tag, ploop1-
4650: 74 61 67 2c 20 70 6c 6f 6f 70 32 2d 74 61 67 2c  tag, ploop2-tag,
4660: 20 70 6c 6f 6f 70 33 2d 74 61 67 27 2c 20 7b 0a   ploop3-tag', {.
4670: 20 20 20 20 20 20 65 6c 65 6d 65 6e 74 73 3a 20        elements: 
4680: 5b 7b 0a 20 20 20 20 20 20 20 20 66 6f 6f 3a 20  [{.        foo: 
4690: 27 66 6f 6f 27 2c 0a 20 20 20 20 20 20 20 20 69  'foo',.        i
46a0: 64 3a 20 30 0a 20 20 20 20 20 20 7d 2c 20 7b 0a  d: 0.      }, {.
46b0: 20 20 20 20 20 20 20 20 66 6f 6f 3a 20 27 62 61          foo: 'ba
46c0: 72 27 2c 0a 20 20 20 20 20 20 20 20 69 64 3a 20  r',.        id: 
46d0: 31 0a 20 20 20 20 20 20 7d 5d 0a 20 20 20 20 7d  1.      }].    }
46e0: 29 0a 0a 20 20 20 20 65 78 70 65 63 74 28 74 61  )..    expect(ta
46f0: 67 5b 30 5d 2e 74 61 67 73 5b 27 70 6c 6f 6f 70  g[0].tags['ploop
4700: 2d 63 68 69 6c 64 27 5d 2e 6c 65 6e 67 74 68 29  -child'].length)
4710: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 32 29 0a  .to.be.equal(2).
4720: 20 20 20 20 65 78 70 65 63 74 28 74 61 67 5b 30      expect(tag[0
4730: 5d 2e 74 61 67 73 5b 27 70 6c 6f 6f 70 2d 61 6e  ].tags['ploop-an
4740: 6f 74 68 65 72 27 5d 29 2e 74 6f 2e 62 65 2e 61  other']).to.be.a
4750: 6e 28 27 6f 62 6a 65 63 74 27 29 0a 20 20 20 20  n('object').    
4760: 65 78 70 65 63 74 28 74 61 67 5b 31 5d 2e 74 61  expect(tag[1].ta
4770: 67 73 5b 27 70 6c 6f 6f 70 2d 63 68 69 6c 64 27  gs['ploop-child'
4780: 5d 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e  ].length).to.be.
4790: 65 71 75 61 6c 28 32 29 0a 20 20 20 20 65 78 70  equal(2).    exp
47a0: 65 63 74 28 74 61 67 5b 31 5d 2e 74 61 67 73 5b  ect(tag[1].tags[
47b0: 27 70 6c 6f 6f 70 2d 61 6e 6f 74 68 65 72 27 5d  'ploop-another']
47c0: 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65  .length).to.be.e
47d0: 71 75 61 6c 28 32 29 0a 20 20 20 20 65 78 70 65  qual(2).    expe
47e0: 63 74 28 74 61 67 5b 32 5d 2e 74 61 67 73 5b 27  ct(tag[2].tags['
47f0: 70 6c 6f 6f 70 2d 63 68 69 6c 64 27 5d 2e 6c 65  ploop-child'].le
4800: 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61  ngth).to.be.equa
4810: 6c 28 32 29 0a 20 20 20 20 65 78 70 65 63 74 28  l(2).    expect(
4820: 74 61 67 5b 32 5d 2e 74 61 67 73 5b 27 70 6c 6f  tag[2].tags['plo
4830: 6f 70 2d 61 6e 6f 74 68 65 72 27 5d 29 2e 74 6f  op-another']).to
4840: 2e 62 65 2e 61 6e 28 27 6f 62 6a 65 63 74 27 29  .be.an('object')
4850: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 5b  .    expect(tag[
4860: 33 5d 2e 74 61 67 73 5b 27 70 6c 6f 6f 70 2d 63  3].tags['ploop-c
4870: 68 69 6c 64 27 5d 2e 6c 65 6e 67 74 68 29 2e 74  hild'].length).t
4880: 6f 2e 62 65 2e 65 71 75 61 6c 28 32 29 0a 20 20  o.be.equal(2).  
4890: 20 20 65 78 70 65 63 74 28 74 61 67 5b 33 5d 2e    expect(tag[3].
48a0: 74 61 67 73 5b 27 70 6c 6f 6f 70 2d 61 6e 6f 74  tags['ploop-anot
48b0: 68 65 72 27 5d 29 2e 74 6f 2e 62 65 2e 61 6e 28  her']).to.be.an(
48c0: 27 6f 62 6a 65 63 74 27 29 0a 0a 20 20 20 20 74  'object')..    t
48d0: 61 67 2e 66 6f 72 45 61 63 68 28 74 61 67 20 3d  ag.forEach(tag =
48e0: 3e 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 29  > tag.unmount())
48f0: 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 64 79 6e  .  })..  it('dyn
4900: 61 6d 69 63 61 6c 6c 79 20 72 65 66 65 72 65 6e  amically referen
4910: 63 65 64 20 65 6c 65 6d 65 6e 74 73 20 69 6e 20  ced elements in 
4920: 61 20 6c 6f 6f 70 27 2c 20 66 75 6e 63 74 69 6f  a loop', functio
4930: 6e 28 29 20 7b 0a 0a 20 20 20 20 69 6e 6a 65 63  n() {..    injec
4940: 74 48 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 6e 61 6d  tHTML('<loop-nam
4950: 65 64 3e 3c 2f 6c 6f 6f 70 2d 6e 61 6d 65 64 3e  ed></loop-named>
4960: 27 29 0a 0a 20 20 20 20 63 6f 6e 73 74 20 74 61  ')..    const ta
4970: 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27  g = riot.mount('
4980: 6c 6f 6f 70 2d 6e 61 6d 65 64 27 29 5b 30 5d 0a  loop-named')[0].
4990: 20 20 20 20 74 61 67 2e 6f 6e 28 27 6d 6f 75 6e      tag.on('moun
49a0: 74 27 2c 20 66 75 6e 63 74 69 6f 6e 20 28 29 20  t', function () 
49b0: 7b 0a 20 20 20 20 20 20 65 78 70 65 63 74 28 74  {.      expect(t
49c0: 61 67 2e 66 69 72 73 74 29 2e 6e 61 6d 65 2e 74  ag.first).name.t
49d0: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 66 69 72 73  o.be.equal('firs
49e0: 74 27 29 0a 20 20 20 20 20 20 65 78 70 65 63 74  t').      expect
49f0: 28 74 61 67 2e 74 77 6f 29 2e 6e 61 6d 65 2e 74  (tag.two).name.t
4a00: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 74 77 6f 27  o.be.equal('two'
4a10: 29 0a 20 20 20 20 7d 29 0a 20 20 20 20 74 61 67  ).    }).    tag
4a20: 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a  .unmount().  }).
4a30: 0a 0a 20 20 69 74 28 27 70 72 6f 74 65 63 74 20  ..  it('protect 
4a40: 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 22 74 61  the internal "ta
4a50: 67 73 22 20 61 74 74 72 69 62 75 74 65 20 66 72  gs" attribute fr
4a60: 6f 6d 20 65 78 74 65 72 6e 61 6c 20 6f 76 65 72  om external over
4a70: 72 69 64 65 73 27 2c 20 66 75 6e 63 74 69 6f 6e  rides', function
4a80: 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48  () {.    injectH
4a90: 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 70 72 6f 74 65  TML('<loop-prote
4aa0: 63 74 2d 69 6e 74 65 72 6e 61 6c 2d 61 74 74 72  ct-internal-attr
4ab0: 73 3e 3c 2f 6c 6f 6f 70 2d 70 72 6f 74 65 63 74  s></loop-protect
4ac0: 2d 69 6e 74 65 72 6e 61 6c 2d 61 74 74 72 73 3e  -internal-attrs>
4ad0: 27 29 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67  ').    const tag
4ae0: 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c   = riot.mount('l
4af0: 6f 6f 70 2d 70 72 6f 74 65 63 74 2d 69 6e 74 65  oop-protect-inte
4b00: 72 6e 61 6c 2d 61 74 74 72 73 27 29 5b 30 5d 0a  rnal-attrs')[0].
4b10: 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 74      expect(tag.t
4b20: 61 67 73 5b 27 6c 6f 6f 70 2d 70 72 6f 74 65 63  ags['loop-protec
4b30: 74 2d 69 6e 74 65 72 6e 61 6c 2d 61 74 74 72 73  t-internal-attrs
4b40: 2d 63 68 69 6c 64 27 5d 2e 6c 65 6e 67 74 68 29  -child'].length)
4b50: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 34 29 0a  .to.be.equal(4).
4b60: 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28      tag.unmount(
4b70: 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 74 68  ).  })..  it('th
4b80: 65 20 22 75 70 64 61 74 65 64 22 20 67 65 74 73  e "updated" gets
4b90: 20 70 72 6f 70 65 72 6c 79 20 74 72 69 67 67 65   properly trigge
4ba0: 72 65 64 20 61 6c 73 6f 20 66 72 6f 6d 20 74 68  red also from th
4bb0: 65 20 63 68 69 6c 64 72 65 6e 20 74 61 67 73 20  e children tags 
4bc0: 69 6e 20 61 20 6c 6f 6f 70 27 2c 20 66 75 6e 63  in a loop', func
4bd0: 74 69 6f 6e 28 64 6f 6e 65 29 20 7b 0a 0a 20 20  tion(done) {..  
4be0: 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 64    injectHTML('<d
4bf0: 69 76 20 69 64 3d 22 75 70 64 61 74 65 64 2d 65  iv id="updated-e
4c00: 76 65 6e 74 73 2d 69 6e 2d 6c 6f 6f 70 22 3e 3c  vents-in-loop"><
4c10: 2f 64 69 76 3e 27 29 0a 20 20 20 20 63 6f 6e 73  /div>').    cons
4c20: 74 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75  t tag = riot.mou
4c30: 6e 74 28 27 23 75 70 64 61 74 65 64 2d 65 76 65  nt('#updated-eve
4c40: 6e 74 73 2d 69 6e 2d 6c 6f 6f 70 27 2c 20 27 6c  nts-in-loop', 'l
4c50: 6f 6f 70 2d 75 6e 73 68 69 66 74 27 29 5b 30 5d  oop-unshift')[0]
4c60: 0a 20 20 20 20 6c 65 74 20 63 6f 75 6e 74 65 72  .    let counter
4c70: 20 3d 20 30 0a 0a 20 20 20 20 74 61 67 2e 74 61   = 0..    tag.ta
4c80: 67 73 5b 27 6c 6f 6f 70 2d 75 6e 73 68 69 66 74  gs['loop-unshift
4c90: 2d 69 74 65 6d 27 5d 5b 30 5d 2e 6f 6e 28 27 75  -item'][0].on('u
4ca0: 70 64 61 74 65 64 27 2c 20 66 75 6e 63 74 69 6f  pdated', functio
4cb0: 6e 28 29 20 7b 0a 20 20 20 20 20 20 63 6f 75 6e  n() {.      coun
4cc0: 74 65 72 20 2b 2b 0a 20 20 20 20 20 20 69 66 20  ter ++.      if 
4cd0: 28 63 6f 75 6e 74 65 72 20 3d 3d 3d 20 32 29 20  (counter === 2) 
4ce0: 64 6f 6e 65 28 29 0a 20 20 20 20 7d 29 0a 0a 20  done().    }).. 
4cf0: 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a     tag.update().
4d00: 20 20 20 20 74 61 67 2e 74 61 67 73 5b 27 6c 6f      tag.tags['lo
4d10: 6f 70 2d 75 6e 73 68 69 66 74 2d 69 74 65 6d 27  op-unshift-item'
4d20: 5d 5b 30 5d 2e 75 70 64 61 74 65 28 29 0a 0a 20  ][0].update().. 
4d30: 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29     tag.unmount()
4d40: 0a 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 74 68  ..  })..  it('th
4d50: 65 20 6c 6f 6f 70 73 20 63 68 69 6c 64 72 65 6e  e loops children
4d60: 20 73 79 6e 63 20 63 6f 72 72 65 63 74 6c 79 20   sync correctly 
4d70: 74 68 65 69 72 20 69 6e 74 65 72 6e 61 6c 20 64  their internal d
4d80: 61 74 61 20 77 69 74 68 20 74 68 65 69 72 20 6f  ata with their o
4d90: 70 74 69 6f 6e 73 27 2c 20 66 75 6e 63 74 69 6f  ptions', functio
4da0: 6e 28 29 20 7b 0a 0a 20 20 20 20 69 6e 6a 65 63  n() {..    injec
4db0: 74 48 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 73 79 6e  tHTML('<loop-syn
4dc0: 63 2d 6f 70 74 69 6f 6e 73 3e 3c 2f 6c 6f 6f 70  c-options></loop
4dd0: 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 3e 27 29  -sync-options>')
4de0: 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d  .    const tag =
4df0: 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f   riot.mount('loo
4e00: 70 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 27 29  p-sync-options')
4e10: 5b 30 5d 0a 0a 20 20 20 20 66 75 6e 63 74 69 6f  [0]..    functio
4e20: 6e 20 63 68 28 69 64 78 29 20 7b 0a 20 20 20 20  n ch(idx) {.    
4e30: 20 20 72 65 74 75 72 6e 20 74 61 67 2e 72 6f 6f    return tag.roo
4e40: 74 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54  t.getElementsByT
4e50: 61 67 4e 61 6d 65 28 27 6c 6f 6f 70 2d 73 79 6e  agName('loop-syn
4e60: 63 2d 6f 70 74 69 6f 6e 73 2d 63 68 69 6c 64 27  c-options-child'
4e70: 29 5b 69 64 78 5d 2e 5f 74 61 67 0a 20 20 20 20  )[idx]._tag.    
4e80: 7d 0a 0a 20 20 20 20 65 78 70 65 63 74 28 63 68  }..    expect(ch
4e90: 28 30 29 2e 76 61 6c 29 2e 74 6f 2e 62 65 2e 65  (0).val).to.be.e
4ea0: 71 75 61 6c 28 27 66 6f 6f 27 29 0a 20 20 20 20  qual('foo').    
4eb0: 65 78 70 65 63 74 28 63 68 28 30 29 2e 72 6f 6f  expect(ch(0).roo
4ec0: 74 2e 63 6c 61 73 73 4e 61 6d 65 29 2e 74 6f 2e  t.className).to.
4ed0: 62 65 2e 65 71 75 61 6c 28 27 61 63 74 69 76 65  be.equal('active
4ee0: 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 63 68  ').    expect(ch
4ef0: 28 31 29 2e 76 61 6c 29 2e 74 6f 2e 62 65 2e 65  (1).val).to.be.e
4f00: 71 75 61 6c 28 75 6e 64 65 66 69 6e 65 64 29 0a  qual(undefined).
4f10: 20 20 20 20 65 78 70 65 63 74 28 63 68 28 32 29      expect(ch(2)
4f20: 2e 76 61 6c 29 2e 74 6f 2e 62 65 2e 65 71 75 61  .val).to.be.equa
4f30: 6c 28 75 6e 64 65 66 69 6e 65 64 29 0a 20 20 20  l(undefined).   
4f40: 20 65 78 70 65 63 74 28 63 68 28 30 29 2e 6e 75   expect(ch(0).nu
4f50: 6d 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75  m).to.be.equal(u
4f60: 6e 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65 78  ndefined).    ex
4f70: 70 65 63 74 28 63 68 28 31 29 2e 6e 75 6d 29 2e  pect(ch(1).num).
4f80: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 33 29 0a 20  to.be.equal(3). 
4f90: 20 20 20 65 78 70 65 63 74 28 63 68 28 32 29 2e     expect(ch(2).
4fa0: 6e 75 6d 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  num).to.be.equal
4fb0: 28 75 6e 64 65 66 69 6e 65 64 29 0a 20 20 20 20  (undefined).    
4fc0: 65 78 70 65 63 74 28 63 68 28 30 29 2e 62 6f 6f  expect(ch(0).boo
4fd0: 6c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75  l).to.be.equal(u
4fe0: 6e 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65 78  ndefined).    ex
4ff0: 70 65 63 74 28 63 68 28 31 29 2e 62 6f 6f 6c 29  pect(ch(1).bool)
5000: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e 64  .to.be.equal(und
5010: 65 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70 65  efined).    expe
5020: 63 74 28 63 68 28 32 29 2e 62 6f 6f 6c 29 2e 74  ct(ch(2).bool).t
5030: 6f 2e 62 65 2e 65 71 75 61 6c 28 66 61 6c 73 65  o.be.equal(false
5040: 29 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74 65  ).    tag.update
5050: 28 7b 0a 20 20 20 20 20 20 63 68 69 6c 64 72 65  ({.      childre
5060: 6e 3a 20 74 61 67 2e 63 68 69 6c 64 72 65 6e 2e  n: tag.children.
5070: 72 65 76 65 72 73 65 28 29 0a 20 20 20 20 7d 29  reverse().    })
5080: 0a 20 20 20 20 65 78 70 65 63 74 28 63 68 28 30  .    expect(ch(0
5090: 29 2e 76 61 6c 29 2e 74 6f 2e 62 65 2e 65 71 75  ).val).to.be.equ
50a0: 61 6c 28 75 6e 64 65 66 69 6e 65 64 29 0a 20 20  al(undefined).  
50b0: 20 20 65 78 70 65 63 74 28 63 68 28 30 29 2e 72    expect(ch(0).r
50c0: 6f 6f 74 2e 63 6c 61 73 73 4e 61 6d 65 29 2e 74  oot.className).t
50d0: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 27 29 0a 20  o.be.equal(''). 
50e0: 20 20 20 65 78 70 65 63 74 28 63 68 28 31 29 2e     expect(ch(1).
50f0: 76 61 6c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  val).to.be.equal
5100: 28 75 6e 64 65 66 69 6e 65 64 29 0a 20 20 20 20  (undefined).    
5110: 65 78 70 65 63 74 28 63 68 28 32 29 2e 76 61 6c  expect(ch(2).val
5120: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 66  ).to.be.equal('f
5130: 6f 6f 27 29 0a 20 20 20 20 65 78 70 65 63 74 28  oo').    expect(
5140: 63 68 28 32 29 2e 72 6f 6f 74 2e 63 6c 61 73 73  ch(2).root.class
5150: 4e 61 6d 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61  Name).to.be.equa
5160: 6c 28 27 61 63 74 69 76 65 27 29 0a 20 20 20 20  l('active').    
5170: 65 78 70 65 63 74 28 63 68 28 30 29 2e 6e 75 6d  expect(ch(0).num
5180: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e  ).to.be.equal(un
5190: 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70  defined).    exp
51a0: 65 63 74 28 63 68 28 31 29 2e 6e 75 6d 29 2e 74  ect(ch(1).num).t
51b0: 6f 2e 62 65 2e 65 71 75 61 6c 28 33 29 0a 20 20  o.be.equal(3).  
51c0: 20 20 65 78 70 65 63 74 28 63 68 28 32 29 2e 6e    expect(ch(2).n
51d0: 75 6d 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  um).to.be.equal(
51e0: 75 6e 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65  undefined).    e
51f0: 78 70 65 63 74 28 63 68 28 30 29 2e 62 6f 6f 6c  xpect(ch(0).bool
5200: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 66 61  ).to.be.equal(fa
5210: 6c 73 65 29 0a 20 20 20 20 65 78 70 65 63 74 28  lse).    expect(
5220: 63 68 28 31 29 2e 62 6f 6f 6c 29 2e 74 6f 2e 62  ch(1).bool).to.b
5230: 65 2e 65 71 75 61 6c 28 75 6e 64 65 66 69 6e 65  e.equal(undefine
5240: 64 29 0a 20 20 20 20 65 78 70 65 63 74 28 63 68  d).    expect(ch
5250: 28 32 29 2e 62 6f 6f 6c 29 2e 74 6f 2e 62 65 2e  (2).bool).to.be.
5260: 65 71 75 61 6c 28 75 6e 64 65 66 69 6e 65 64 29  equal(undefined)
5270: 0a 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74 65  ..    tag.update
5280: 28 7b 0a 20 20 20 20 20 20 63 68 69 6c 64 72 65  ({.      childre
5290: 6e 3a 20 74 61 67 2e 63 68 69 6c 64 72 65 6e 2e  n: tag.children.
52a0: 72 65 76 65 72 73 65 28 29 0a 20 20 20 20 7d 29  reverse().    })
52b0: 0a 20 20 20 20 65 78 70 65 63 74 28 63 68 28 30  .    expect(ch(0
52c0: 29 2e 76 61 6c 29 2e 74 6f 2e 62 65 2e 65 71 75  ).val).to.be.equ
52d0: 61 6c 28 27 66 6f 6f 27 29 0a 20 20 20 20 65 78  al('foo').    ex
52e0: 70 65 63 74 28 63 68 28 30 29 2e 72 6f 6f 74 2e  pect(ch(0).root.
52f0: 63 6c 61 73 73 4e 61 6d 65 29 2e 74 6f 2e 62 65  className).to.be
5300: 2e 65 71 75 61 6c 28 27 61 63 74 69 76 65 27 29  .equal('active')
5310: 0a 20 20 20 20 65 78 70 65 63 74 28 63 68 28 31  .    expect(ch(1
5320: 29 2e 76 61 6c 29 2e 74 6f 2e 62 65 2e 65 71 75  ).val).to.be.equ
5330: 61 6c 28 75 6e 64 65 66 69 6e 65 64 29 0a 20 20  al(undefined).  
5340: 20 20 65 78 70 65 63 74 28 63 68 28 32 29 2e 76    expect(ch(2).v
5350: 61 6c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  al).to.be.equal(
5360: 75 6e 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65  undefined).    e
5370: 78 70 65 63 74 28 63 68 28 32 29 2e 72 6f 6f 74  xpect(ch(2).root
5380: 2e 63 6c 61 73 73 4e 61 6d 65 29 2e 74 6f 2e 62  .className).to.b
5390: 65 2e 65 71 75 61 6c 28 27 27 29 0a 20 20 20 20  e.equal('').    
53a0: 65 78 70 65 63 74 28 63 68 28 30 29 2e 6e 75 6d  expect(ch(0).num
53b0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e  ).to.be.equal(un
53c0: 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70  defined).    exp
53d0: 65 63 74 28 63 68 28 31 29 2e 6e 75 6d 29 2e 74  ect(ch(1).num).t
53e0: 6f 2e 62 65 2e 65 71 75 61 6c 28 33 29 0a 20 20  o.be.equal(3).  
53f0: 20 20 65 78 70 65 63 74 28 63 68 28 32 29 2e 6e    expect(ch(2).n
5400: 75 6d 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  um).to.be.equal(
5410: 75 6e 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65  undefined).    e
5420: 78 70 65 63 74 28 63 68 28 30 29 2e 62 6f 6f 6c  xpect(ch(0).bool
5430: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e  ).to.be.equal(un
5440: 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70  defined).    exp
5450: 65 63 74 28 63 68 28 31 29 2e 62 6f 6f 6c 29 2e  ect(ch(1).bool).
5460: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e 64 65  to.be.equal(unde
5470: 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70 65 63  fined).    expec
5480: 74 28 63 68 28 32 29 2e 62 6f 6f 6c 29 2e 74 6f  t(ch(2).bool).to
5490: 2e 62 65 2e 65 71 75 61 6c 28 66 61 6c 73 65 29  .be.equal(false)
54a0: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
54b0: 28 29 0a 20 20 7d 29 0a 0a 0a 20 20 69 74 28 27  ().  })...  it('
54c0: 74 68 65 20 6c 6f 6f 70 73 20 63 68 69 6c 64 72  the loops childr
54d0: 65 6e 20 73 79 6e 63 20 63 6f 72 72 65 63 74 6c  en sync correctl
54e0: 79 20 74 68 65 69 72 20 69 6e 74 65 72 6e 61 6c  y their internal
54f0: 20 64 61 74 61 20 65 76 65 6e 20 77 68 65 6e 20   data even when 
5500: 74 68 65 79 20 61 72 65 20 6e 65 73 74 65 64 27  they are nested'
5510: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 0a  , function() {..
5520: 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27      injectHTML('
5530: 3c 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70 74 69 6f  <loop-sync-optio
5540: 6e 73 2d 6e 65 73 74 65 64 3e 3c 2f 6c 6f 6f 70  ns-nested></loop
5550: 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65  -sync-options-ne
5560: 73 74 65 64 3e 27 29 0a 20 20 20 20 63 6f 6e 73  sted>').    cons
5570: 74 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75  t tag = riot.mou
5580: 6e 74 28 27 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70  nt('loop-sync-op
5590: 74 69 6f 6e 73 2d 6e 65 73 74 65 64 27 29 5b 30  tions-nested')[0
55a0: 5d 0a 0a 20 20 20 20 65 78 70 65 63 74 28 74 61  ]..    expect(ta
55b0: 67 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 73 79 6e  g.tags['loop-syn
55c0: 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65 64  c-options-nested
55d0: 2d 63 68 69 6c 64 27 5d 5b 30 5d 2e 70 61 72 65  -child'][0].pare
55e0: 6e 74 2e 72 6f 6f 74 2e 74 61 67 4e 61 6d 65 2e  nt.root.tagName.
55f0: 74 6f 4c 6f 77 65 72 43 61 73 65 28 29 29 2e 74  toLowerCase()).t
5600: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 6c 6f 6f 70  o.be.equal('loop
5610: 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65  -sync-options-ne
5620: 73 74 65 64 27 29 0a 20 20 20 20 65 78 70 65 63  sted').    expec
5630: 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70  t(tag.tags['loop
5640: 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65  -sync-options-ne
5650: 73 74 65 64 2d 63 68 69 6c 64 27 5d 5b 30 5d 2e  sted-child'][0].
5660: 76 61 6c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  val).to.be.equal
5670: 28 27 66 6f 6f 27 29 0a 20 20 20 20 65 78 70 65  ('foo').    expe
5680: 63 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f  ct(tag.tags['loo
5690: 70 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e  p-sync-options-n
56a0: 65 73 74 65 64 2d 63 68 69 6c 64 27 5d 5b 31 5d  ested-child'][1]
56b0: 2e 76 61 6c 29 2e 74 6f 2e 62 65 2e 65 71 75 61  .val).to.be.equa
56c0: 6c 28 75 6e 64 65 66 69 6e 65 64 29 0a 20 20 20  l(undefined).   
56d0: 20 65 78 70 65 63 74 28 74 61 67 2e 74 61 67 73   expect(tag.tags
56e0: 5b 27 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70 74 69  ['loop-sync-opti
56f0: 6f 6e 73 2d 6e 65 73 74 65 64 2d 63 68 69 6c 64  ons-nested-child
5700: 27 5d 5b 32 5d 2e 76 61 6c 29 2e 74 6f 2e 62 65  '][2].val).to.be
5710: 2e 65 71 75 61 6c 28 75 6e 64 65 66 69 6e 65 64  .equal(undefined
5720: 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67  ).    expect(tag
5730: 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 73 79 6e 63  .tags['loop-sync
5740: 2d 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65 64 2d  -options-nested-
5750: 63 68 69 6c 64 27 5d 5b 30 5d 2e 6e 75 6d 29 2e  child'][0].num).
5760: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e 64 65  to.be.equal(unde
5770: 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70 65 63  fined).    expec
5780: 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70  t(tag.tags['loop
5790: 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65  -sync-options-ne
57a0: 73 74 65 64 2d 63 68 69 6c 64 27 5d 5b 31 5d 2e  sted-child'][1].
57b0: 6e 75 6d 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  num).to.be.equal
57c0: 28 33 29 0a 20 20 20 20 65 78 70 65 63 74 28 74  (3).    expect(t
57d0: 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 73 79  ag.tags['loop-sy
57e0: 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65  nc-options-neste
57f0: 64 2d 63 68 69 6c 64 27 5d 5b 32 5d 2e 6e 75 6d  d-child'][2].num
5800: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e  ).to.be.equal(un
5810: 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70  defined).    exp
5820: 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f  ect(tag.tags['lo
5830: 6f 70 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d  op-sync-options-
5840: 6e 65 73 74 65 64 2d 63 68 69 6c 64 27 5d 5b 30  nested-child'][0
5850: 5d 2e 62 6f 6f 6c 29 2e 74 6f 2e 62 65 2e 65 71  ].bool).to.be.eq
5860: 75 61 6c 28 75 6e 64 65 66 69 6e 65 64 29 0a 20  ual(undefined). 
5870: 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 74 61     expect(tag.ta
5880: 67 73 5b 27 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70  gs['loop-sync-op
5890: 74 69 6f 6e 73 2d 6e 65 73 74 65 64 2d 63 68 69  tions-nested-chi
58a0: 6c 64 27 5d 5b 31 5d 2e 62 6f 6f 6c 29 2e 74 6f  ld'][1].bool).to
58b0: 2e 62 65 2e 65 71 75 61 6c 28 75 6e 64 65 66 69  .be.equal(undefi
58c0: 6e 65 64 29 0a 20 20 20 20 65 78 70 65 63 74 28  ned).    expect(
58d0: 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 73  tag.tags['loop-s
58e0: 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65 73 74  ync-options-nest
58f0: 65 64 2d 63 68 69 6c 64 27 5d 5b 32 5d 2e 62 6f  ed-child'][2].bo
5900: 6f 6c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  ol).to.be.equal(
5910: 66 61 6c 73 65 29 0a 20 20 20 20 74 61 67 2e 75  false).    tag.u
5920: 70 64 61 74 65 28 7b 0a 20 20 20 20 20 20 63 68  pdate({.      ch
5930: 69 6c 64 72 65 6e 3a 20 74 61 67 2e 63 68 69 6c  ildren: tag.chil
5940: 64 72 65 6e 2e 72 65 76 65 72 73 65 28 29 0a 20  dren.reverse(). 
5950: 20 20 20 7d 29 0a 20 20 20 20 74 61 67 2e 75 70     }).    tag.up
5960: 64 61 74 65 28 29 0a 20 20 20 20 65 78 70 65 63  date().    expec
5970: 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70  t(tag.tags['loop
5980: 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65  -sync-options-ne
5990: 73 74 65 64 2d 63 68 69 6c 64 27 5d 5b 30 5d 2e  sted-child'][0].
59a0: 76 61 6c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  val).to.be.equal
59b0: 28 75 6e 64 65 66 69 6e 65 64 29 0a 20 20 20 20  (undefined).    
59c0: 65 78 70 65 63 74 28 74 61 67 2e 74 61 67 73 5b  expect(tag.tags[
59d0: 27 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70 74 69 6f  'loop-sync-optio
59e0: 6e 73 2d 6e 65 73 74 65 64 2d 63 68 69 6c 64 27  ns-nested-child'
59f0: 5d 5b 31 5d 2e 76 61 6c 29 2e 74 6f 2e 62 65 2e  ][1].val).to.be.
5a00: 65 71 75 61 6c 28 75 6e 64 65 66 69 6e 65 64 29  equal(undefined)
5a10: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e  .    expect(tag.
5a20: 74 61 67 73 5b 27 6c 6f 6f 70 2d 73 79 6e 63 2d  tags['loop-sync-
5a30: 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65 64 2d 63  options-nested-c
5a40: 68 69 6c 64 27 5d 5b 32 5d 2e 76 61 6c 29 2e 74  hild'][2].val).t
5a50: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 66 6f 6f 27  o.be.equal('foo'
5a60: 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67  ).    expect(tag
5a70: 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 73 79 6e 63  .tags['loop-sync
5a80: 2d 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65 64 2d  -options-nested-
5a90: 63 68 69 6c 64 27 5d 5b 30 5d 2e 6e 75 6d 29 2e  child'][0].num).
5aa0: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e 64 65  to.be.equal(unde
5ab0: 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70 65 63  fined).    expec
5ac0: 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70  t(tag.tags['loop
5ad0: 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65  -sync-options-ne
5ae0: 73 74 65 64 2d 63 68 69 6c 64 27 5d 5b 31 5d 2e  sted-child'][1].
5af0: 6e 75 6d 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  num).to.be.equal
5b00: 28 33 29 0a 20 20 20 20 65 78 70 65 63 74 28 74  (3).    expect(t
5b10: 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 73 79  ag.tags['loop-sy
5b20: 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65  nc-options-neste
5b30: 64 2d 63 68 69 6c 64 27 5d 5b 32 5d 2e 6e 75 6d  d-child'][2].num
5b40: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e  ).to.be.equal(un
5b50: 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70  defined).    exp
5b60: 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f  ect(tag.tags['lo
5b70: 6f 70 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d  op-sync-options-
5b80: 6e 65 73 74 65 64 2d 63 68 69 6c 64 27 5d 5b 30  nested-child'][0
5b90: 5d 2e 62 6f 6f 6c 29 2e 74 6f 2e 62 65 2e 65 71  ].bool).to.be.eq
5ba0: 75 61 6c 28 66 61 6c 73 65 29 0a 20 20 20 20 65  ual(false).    e
5bb0: 78 70 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27  xpect(tag.tags['
5bc0: 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e  loop-sync-option
5bd0: 73 2d 6e 65 73 74 65 64 2d 63 68 69 6c 64 27 5d  s-nested-child']
5be0: 5b 31 5d 2e 62 6f 6f 6c 29 2e 74 6f 2e 62 65 2e  [1].bool).to.be.
5bf0: 65 71 75 61 6c 28 75 6e 64 65 66 69 6e 65 64 29  equal(undefined)
5c00: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e  .    expect(tag.
5c10: 74 61 67 73 5b 27 6c 6f 6f 70 2d 73 79 6e 63 2d  tags['loop-sync-
5c20: 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65 64 2d 63  options-nested-c
5c30: 68 69 6c 64 27 5d 5b 32 5d 2e 62 6f 6f 6c 29 2e  hild'][2].bool).
5c40: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e 64 65  to.be.equal(unde
5c50: 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70 65 63  fined).    expec
5c60: 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70  t(tag.tags['loop
5c70: 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65  -sync-options-ne
5c80: 73 74 65 64 2d 63 68 69 6c 64 27 5d 5b 32 5d 2e  sted-child'][2].
5c90: 70 61 72 65 6e 74 2e 72 6f 6f 74 2e 74 61 67 4e  parent.root.tagN
5ca0: 61 6d 65 2e 74 6f 4c 6f 77 65 72 43 61 73 65 28  ame.toLowerCase(
5cb0: 29 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  )).to.be.equal('
5cc0: 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e  loop-sync-option
5cd0: 73 2d 6e 65 73 74 65 64 27 29 0a 20 20 20 20 74  s-nested').    t
5ce0: 61 67 2e 75 70 64 61 74 65 28 7b 0a 20 20 20 20  ag.update({.    
5cf0: 20 20 63 68 69 6c 64 72 65 6e 3a 20 74 61 67 2e    children: tag.
5d00: 63 68 69 6c 64 72 65 6e 2e 72 65 76 65 72 73 65  children.reverse
5d10: 28 29 0a 20 20 20 20 7d 29 0a 20 20 20 20 74 61  ().    }).    ta
5d20: 67 2e 75 70 64 61 74 65 28 29 0a 20 20 20 20 65  g.update().    e
5d30: 78 70 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27  xpect(tag.tags['
5d40: 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e  loop-sync-option
5d50: 73 2d 6e 65 73 74 65 64 2d 63 68 69 6c 64 27 5d  s-nested-child']
5d60: 5b 30 5d 2e 76 61 6c 29 2e 74 6f 2e 62 65 2e 65  [0].val).to.be.e
5d70: 71 75 61 6c 28 27 66 6f 6f 27 29 0a 20 20 20 20  qual('foo').    
5d80: 65 78 70 65 63 74 28 74 61 67 2e 74 61 67 73 5b  expect(tag.tags[
5d90: 27 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70 74 69 6f  'loop-sync-optio
5da0: 6e 73 2d 6e 65 73 74 65 64 2d 63 68 69 6c 64 27  ns-nested-child'
5db0: 5d 5b 31 5d 2e 76 61 6c 29 2e 74 6f 2e 62 65 2e  ][1].val).to.be.
5dc0: 65 71 75 61 6c 28 75 6e 64 65 66 69 6e 65 64 29  equal(undefined)
5dd0: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e  .    expect(tag.
5de0: 74 61 67 73 5b 27 6c 6f 6f 70 2d 73 79 6e 63 2d  tags['loop-sync-
5df0: 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65 64 2d 63  options-nested-c
5e00: 68 69 6c 64 27 5d 5b 32 5d 2e 76 61 6c 29 2e 74  hild'][2].val).t
5e10: 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e 64 65 66  o.be.equal(undef
5e20: 69 6e 65 64 29 0a 20 20 20 20 65 78 70 65 63 74  ined).    expect
5e30: 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d  (tag.tags['loop-
5e40: 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65 73  sync-options-nes
5e50: 74 65 64 2d 63 68 69 6c 64 27 5d 5b 30 5d 2e 6e  ted-child'][0].n
5e60: 75 6d 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  um).to.be.equal(
5e70: 75 6e 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65  undefined).    e
5e80: 78 70 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27  xpect(tag.tags['
5e90: 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e  loop-sync-option
5ea0: 73 2d 6e 65 73 74 65 64 2d 63 68 69 6c 64 27 5d  s-nested-child']
5eb0: 5b 31 5d 2e 6e 75 6d 29 2e 74 6f 2e 62 65 2e 65  [1].num).to.be.e
5ec0: 71 75 61 6c 28 33 29 0a 20 20 20 20 65 78 70 65  qual(3).    expe
5ed0: 63 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f  ct(tag.tags['loo
5ee0: 70 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e  p-sync-options-n
5ef0: 65 73 74 65 64 2d 63 68 69 6c 64 27 5d 5b 32 5d  ested-child'][2]
5f00: 2e 6e 75 6d 29 2e 74 6f 2e 62 65 2e 65 71 75 61  .num).to.be.equa
5f10: 6c 28 75 6e 64 65 66 69 6e 65 64 29 0a 20 20 20  l(undefined).   
5f20: 20 65 78 70 65 63 74 28 74 61 67 2e 74 61 67 73   expect(tag.tags
5f30: 5b 27 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70 74 69  ['loop-sync-opti
5f40: 6f 6e 73 2d 6e 65 73 74 65 64 2d 63 68 69 6c 64  ons-nested-child
5f50: 27 5d 5b 30 5d 2e 62 6f 6f 6c 29 2e 74 6f 2e 62  '][0].bool).to.b
5f60: 65 2e 65 71 75 61 6c 28 75 6e 64 65 66 69 6e 65  e.equal(undefine
5f70: 64 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61  d).    expect(ta
5f80: 67 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 73 79 6e  g.tags['loop-syn
5f90: 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65 64  c-options-nested
5fa0: 2d 63 68 69 6c 64 27 5d 5b 31 5d 2e 62 6f 6f 6c  -child'][1].bool
5fb0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 75 6e  ).to.be.equal(un
5fc0: 64 65 66 69 6e 65 64 29 0a 20 20 20 20 65 78 70  defined).    exp
5fd0: 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f  ect(tag.tags['lo
5fe0: 6f 70 2d 73 79 6e 63 2d 6f 70 74 69 6f 6e 73 2d  op-sync-options-
5ff0: 6e 65 73 74 65 64 2d 63 68 69 6c 64 27 5d 5b 32  nested-child'][2
6000: 5d 2e 62 6f 6f 6c 29 2e 74 6f 2e 62 65 2e 65 71  ].bool).to.be.eq
6010: 75 61 6c 28 66 61 6c 73 65 29 0a 0a 20 20 20 20  ual(false)..    
6020: 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20  tag.unmount().  
6030: 7d 29 0a 0a 20 20 69 74 28 27 74 68 65 20 63 68  })..  it('the ch
6040: 69 6c 64 72 65 6e 20 74 61 67 73 20 61 72 65 20  ildren tags are 
6050: 69 6e 20 73 79 6e 63 20 61 6c 73 6f 20 69 6e 20  in sync also in 
6060: 6d 75 6c 74 69 70 6c 65 20 6e 65 73 74 65 64 20  multiple nested 
6070: 74 61 67 73 27 2c 20 66 75 6e 63 74 69 6f 6e 28  tags', function(
6080: 29 20 7b 0a 0a 20 20 20 20 69 6e 6a 65 63 74 48  ) {..    injectH
6090: 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 73 79 6e 63 2d  TML('<loop-sync-
60a0: 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65 64 2d 77  options-nested-w
60b0: 72 61 70 70 65 72 3e 3c 2f 6c 6f 6f 70 2d 73 79  rapper></loop-sy
60c0: 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65  nc-options-neste
60d0: 64 2d 77 72 61 70 70 65 72 3e 27 29 0a 20 20 20  d-wrapper>').   
60e0: 20 63 6f 6e 73 74 20 74 61 67 20 3d 20 72 69 6f   const tag = rio
60f0: 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d 73 79  t.mount('loop-sy
6100: 6e 63 2d 6f 70 74 69 6f 6e 73 2d 6e 65 73 74 65  nc-options-neste
6110: 64 2d 77 72 61 70 70 65 72 27 29 5b 30 5d 0a 20  d-wrapper')[0]. 
6120: 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 74 61     expect(tag.ta
6130: 67 73 5b 27 6c 6f 6f 70 2d 73 79 6e 63 2d 6f 70  gs['loop-sync-op
6140: 74 69 6f 6e 73 2d 6e 65 73 74 65 64 27 5d 2e 74  tions-nested'].t
6150: 61 67 73 5b 27 6c 6f 6f 70 2d 73 79 6e 63 2d 6f  ags['loop-sync-o
6160: 70 74 69 6f 6e 73 2d 6e 65 73 74 65 64 2d 63 68  ptions-nested-ch
6170: 69 6c 64 27 5d 2e 6c 65 6e 67 74 68 29 2e 74 6f  ild'].length).to
6180: 2e 62 65 2e 65 71 75 61 6c 28 33 29 0a 20 20 20  .be.equal(3).   
6190: 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20   tag.unmount(). 
61a0: 20 7d 29 0a 0a 20 20 69 74 28 27 6c 6f 6f 70 65   })..  it('loope
61b0: 64 20 6f 70 74 69 6f 6e 73 20 62 65 74 77 65 65  d options betwee
61c0: 6e 20 6f 74 68 65 72 20 6f 70 74 69 6f 6e 73 20  n other options 
61d0: 67 65 74 20 69 6e 73 65 72 74 65 64 20 63 6f 72  get inserted cor
61e0: 72 65 63 74 6c 79 27 2c 20 66 75 6e 63 74 69 6f  rectly', functio
61f0: 6e 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74  n() {.    inject
6200: 48 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 6e 6f 6c 6f  HTML('<loop-nolo
6210: 6f 70 2d 6f 70 74 69 6f 6e 3e 3c 2f 6c 6f 6f 70  op-option></loop
6220: 2d 6e 6f 6c 6f 6f 70 2d 6f 70 74 69 6f 6e 3e 27  -noloop-option>'
6230: 29 0a 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67  )..    const tag
6240: 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c   = riot.mount('l
6250: 6f 6f 70 2d 6e 6f 6c 6f 6f 70 2d 6f 70 74 69 6f  oop-noloop-optio
6260: 6e 27 29 5b 30 5d 0a 20 20 20 20 76 61 72 20 6f  n')[0].    var o
6270: 70 74 69 6f 6e 73 20 3d 20 24 24 28 27 6f 70 74  ptions = $$('opt
6280: 69 6f 6e 27 2c 20 74 61 67 2e 72 6f 6f 74 29 0a  ion', tag.root).
6290: 20 20 20 20 65 78 70 65 63 74 28 6f 70 74 69 6f      expect(optio
62a0: 6e 73 5b 31 5d 2e 76 61 6c 75 65 29 2e 74 6f 2e  ns[1].value).to.
62b0: 62 65 2e 65 71 75 61 6c 28 27 31 27 29 0a 0a 20  be.equal('1').. 
62c0: 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29     tag.unmount()
62d0: 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 63 68 69  .  })..  it('chi
62e0: 6c 64 72 65 6e 20 69 6e 20 61 20 6c 6f 6f 70 20  ldren in a loop 
62f0: 69 6e 68 65 72 69 74 20 70 72 6f 70 65 72 74 69  inherit properti
6300: 65 73 20 66 72 6f 6d 20 74 68 65 20 70 61 72 65  es from the pare
6310: 6e 74 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20  nt', function() 
6320: 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c  {.    injectHTML
6330: 28 27 3c 6c 6f 6f 70 2d 69 6e 68 65 72 69 74 3e  ('<loop-inherit>
6340: 3c 2f 6c 6f 6f 70 2d 69 6e 68 65 72 69 74 3e 27  </loop-inherit>'
6350: 29 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20  ).    const tag 
6360: 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f  = riot.mount('lo
6370: 6f 70 2d 69 6e 68 65 72 69 74 27 29 5b 30 5d 0a  op-inherit')[0].
6380: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e  .    expect(tag.
6390: 72 65 66 73 2e 6d 65 2e 6f 70 74 73 2e 6e 69 63  refs.me.opts.nic
63a0: 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74  e).to.be.equal(t
63b0: 61 67 2e 69 73 46 75 6e 29 0a 20 20 20 20 74 61  ag.isFun).    ta
63c0: 67 2e 69 73 46 75 6e 20 3d 20 66 61 6c 73 65 0a  g.isFun = false.
63d0: 20 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 29      tag.update()
63e0: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e  .    expect(tag.
63f0: 72 65 66 73 2e 6d 65 2e 6f 70 74 73 2e 6e 69 63  refs.me.opts.nic
6400: 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74  e).to.be.equal(t
6410: 61 67 2e 69 73 46 75 6e 29 0a 20 20 20 20 65 78  ag.isFun).    ex
6420: 70 65 63 74 28 74 61 67 2e 72 65 66 73 2e 6d 65  pect(tag.refs.me
6430: 2e 74 61 67 73 29 2e 74 6f 2e 62 65 2e 65 6d 70  .tags).to.be.emp
6440: 74 79 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75  ty.    tag.unmou
6450: 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28  nt().  })..  it(
6460: 27 6c 6f 6f 70 20 74 61 67 73 20 67 65 74 20 72  'loop tags get r
6470: 65 6e 64 65 72 65 64 20 63 6f 72 72 65 63 74 6c  endered correctl
6480: 79 20 61 6c 73 6f 20 77 69 74 68 20 63 6f 6e 64  y also with cond
6490: 69 74 69 6f 6e 61 6c 20 61 74 74 72 69 62 75 74  itional attribut
64a0: 65 73 27 2c 20 66 75 6e 63 74 69 6f 6e 28 64 6f  es', function(do
64b0: 6e 65 29 20 7b 0a 0a 20 20 20 20 69 6e 6a 65 63  ne) {..    injec
64c0: 74 48 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 63 6f 6e  tHTML('<loop-con
64d0: 64 69 74 69 6f 6e 61 6c 3e 3c 2f 6c 6f 6f 70 2d  ditional></loop-
64e0: 63 6f 6e 64 69 74 69 6f 6e 61 6c 3e 27 29 0a 0a  conditional>')..
64f0: 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d 20      const tag = 
6500: 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70  riot.mount('loop
6510: 2d 63 6f 6e 64 69 74 69 6f 6e 61 6c 27 29 5b 30  -conditional')[0
6520: 5d 0a 0a 20 20 20 20 73 65 74 54 69 6d 65 6f 75  ]..    setTimeou
6530: 74 28 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20  t(function() {. 
6540: 20 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e       expect(tag.
6550: 72 6f 6f 74 2e 67 65 74 45 6c 65 6d 65 6e 74 73  root.getElements
6560: 42 79 54 61 67 4e 61 6d 65 28 27 64 69 76 27 29  ByTagName('div')
6570: 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65  .length).to.be.e
6580: 71 75 61 6c 28 32 29 0a 20 20 20 20 20 20 65 78  qual(2).      ex
6590: 70 65 63 74 28 74 61 67 2e 72 6f 6f 74 2e 67 65  pect(tag.root.ge
65a0: 74 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61  tElementsByTagNa
65b0: 6d 65 28 27 6c 6f 6f 70 2d 63 6f 6e 64 69 74 69  me('loop-conditi
65c0: 6f 6e 61 6c 2d 69 74 65 6d 27 29 2e 6c 65 6e 67  onal-item').leng
65d0: 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  th).to.be.equal(
65e0: 32 29 0a 20 20 20 20 20 20 65 78 70 65 63 74 28  2).      expect(
65f0: 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 63  tag.tags['loop-c
6600: 6f 6e 64 69 74 69 6f 6e 61 6c 2d 69 74 65 6d 27  onditional-item'
6610: 5d 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e  ].length).to.be.
6620: 65 71 75 61 6c 28 32 29 0a 20 20 20 20 20 20 65  equal(2).      e
6630: 78 70 65 63 74 28 74 61 67 2e 72 65 66 73 2e 61  xpect(tag.refs.a
6640: 72 74 69 63 6c 65 29 2e 74 6f 2e 68 61 76 65 2e  rticle).to.have.
6650: 6c 65 6e 67 74 68 28 74 61 67 2e 69 74 65 6d 73  length(tag.items
6660: 2e 6c 65 6e 67 74 68 29 0a 0a 20 20 20 20 20 20  .length)..      
6670: 74 61 67 2e 69 74 65 6d 73 20 3d 20 5b 5d 0a 20  tag.items = []. 
6680: 20 20 20 20 20 74 61 67 2e 75 70 64 61 74 65 28       tag.update(
6690: 29 0a 20 20 20 20 20 20 65 78 70 65 63 74 28 74  ).      expect(t
66a0: 61 67 2e 72 6f 6f 74 2e 67 65 74 45 6c 65 6d 65  ag.root.getEleme
66b0: 6e 74 73 42 79 54 61 67 4e 61 6d 65 28 27 64 69  ntsByTagName('di
66c0: 76 27 29 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62  v').length).to.b
66d0: 65 2e 65 71 75 61 6c 28 30 29 0a 20 20 20 20 20  e.equal(0).     
66e0: 20 65 78 70 65 63 74 28 74 61 67 2e 72 6f 6f 74   expect(tag.root
66f0: 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61  .getElementsByTa
6700: 67 4e 61 6d 65 28 27 6c 6f 6f 70 2d 63 6f 6e 64  gName('loop-cond
6710: 69 74 69 6f 6e 61 6c 2d 69 74 65 6d 27 29 2e 6c  itional-item').l
6720: 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75  ength).to.be.equ
6730: 61 6c 28 30 29 0a 20 20 20 20 20 20 65 78 70 65  al(0).      expe
6740: 63 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f  ct(tag.tags['loo
6750: 70 2d 63 6f 6e 64 69 74 69 6f 6e 61 6c 2d 69 74  p-conditional-it
6760: 65 6d 27 5d 29 2e 74 6f 2e 62 65 2e 65 71 75 61  em']).to.be.equa
6770: 6c 28 75 6e 64 65 66 69 6e 65 64 29 0a 20 20 20  l(undefined).   
6780: 20 20 20 74 61 67 2e 69 74 65 6d 73 20 3d 20 5b     tag.items = [
6790: 7b 76 61 6c 75 65 3a 20 32 7d 2c 20 7b 76 61 6c  {value: 2}, {val
67a0: 75 65 3a 20 32 7d 2c 20 7b 76 61 6c 75 65 3a 20  ue: 2}, {value: 
67b0: 32 7d 5d 0a 20 20 20 20 20 20 74 61 67 2e 75 70  2}].      tag.up
67c0: 64 61 74 65 28 29 0a 20 20 20 20 20 20 65 78 70  date().      exp
67d0: 65 63 74 28 74 61 67 2e 72 6f 6f 74 2e 67 65 74  ect(tag.root.get
67e0: 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d  ElementsByTagNam
67f0: 65 28 27 64 69 76 27 29 2e 6c 65 6e 67 74 68 29  e('div').length)
6800: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 33 29 0a  .to.be.equal(3).
6810: 20 20 20 20 20 20 65 78 70 65 63 74 28 74 61 67        expect(tag
6820: 2e 72 6f 6f 74 2e 67 65 74 45 6c 65 6d 65 6e 74  .root.getElement
6830: 73 42 79 54 61 67 4e 61 6d 65 28 27 6c 6f 6f 70  sByTagName('loop
6840: 2d 63 6f 6e 64 69 74 69 6f 6e 61 6c 2d 69 74 65  -conditional-ite
6850: 6d 27 29 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62  m').length).to.b
6860: 65 2e 65 71 75 61 6c 28 33 29 0a 20 20 20 20 20  e.equal(3).     
6870: 20 65 78 70 65 63 74 28 74 61 67 2e 74 61 67 73   expect(tag.tags
6880: 5b 27 6c 6f 6f 70 2d 63 6f 6e 64 69 74 69 6f 6e  ['loop-condition
6890: 61 6c 2d 69 74 65 6d 27 5d 2e 6c 65 6e 67 74 68  al-item'].length
68a0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 33 29  ).to.be.equal(3)
68b0: 0a 20 20 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75  .      tag.unmou
68c0: 6e 74 28 29 0a 20 20 20 20 20 20 64 6f 6e 65 28  nt().      done(
68d0: 29 0a 20 20 20 20 7d 2c 20 31 30 30 29 0a 20 20  ).    }, 100).  
68e0: 7d 29 0a 0a 0a 20 20 69 74 28 27 63 75 73 74 6f  })...  it('custo
68f0: 6d 20 63 68 69 6c 64 72 65 6e 20 69 74 65 6d 73  m children items
6900: 20 69 6e 20 61 20 6e 65 73 74 65 64 20 6c 6f 6f   in a nested loo
6910: 70 20 61 72 65 20 61 6c 77 61 79 73 20 69 6e 20  p are always in 
6920: 73 79 6e 63 20 77 69 74 68 20 74 68 65 20 70 61  sync with the pa
6930: 72 65 6e 74 20 74 61 67 27 2c 20 66 75 6e 63 74  rent tag', funct
6940: 69 6f 6e 28 29 20 7b 0a 0a 20 20 20 20 69 6e 6a  ion() {..    inj
6950: 65 63 74 48 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 69  ectHTML('<loop-i
6960: 6e 68 65 72 69 74 3e 3c 2f 6c 6f 6f 70 2d 69 6e  nherit></loop-in
6970: 68 65 72 69 74 3e 27 29 0a 0a 20 20 20 20 63 6f  herit>')..    co
6980: 6e 73 74 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d  nst tag = riot.m
6990: 6f 75 6e 74 28 27 6c 6f 6f 70 2d 69 6e 68 65 72  ount('loop-inher
69a0: 69 74 27 29 5b 30 5d 0a 0a 20 20 20 20 65 78 70  it')[0]..    exp
69b0: 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f  ect(tag.tags['lo
69c0: 6f 70 2d 69 6e 68 65 72 69 74 2d 69 74 65 6d 27  op-inherit-item'
69d0: 5d 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e  ].length).to.be.
69e0: 65 71 75 61 6c 28 34 29 0a 20 20 20 20 65 78 70  equal(4).    exp
69f0: 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f  ect(tag.tags['lo
6a00: 6f 70 2d 69 6e 68 65 72 69 74 2d 69 74 65 6d 27  op-inherit-item'
6a10: 5d 5b 31 5d 2e 6f 70 74 73 2e 6e 61 6d 65 29 2e  ][1].opts.name).
6a20: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 67 2e  to.be.equal(tag.
6a30: 69 74 65 6d 73 5b 30 5d 29 0a 20 20 20 20 65 78  items[0]).    ex
6a40: 70 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27 6c  pect(tag.tags['l
6a50: 6f 6f 70 2d 69 6e 68 65 72 69 74 2d 69 74 65 6d  oop-inherit-item
6a60: 27 5d 5b 32 5d 2e 6f 70 74 73 2e 6e 61 6d 65 29  '][2].opts.name)
6a70: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 67  .to.be.equal(tag
6a80: 2e 69 74 65 6d 73 5b 31 5d 29 0a 20 20 20 20 65  .items[1]).    e
6a90: 78 70 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27  xpect(tag.tags['
6aa0: 6c 6f 6f 70 2d 69 6e 68 65 72 69 74 2d 69 74 65  loop-inherit-ite
6ab0: 6d 27 5d 5b 33 5d 2e 6f 70 74 73 2e 6e 61 6d 65  m'][3].opts.name
6ac0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61  ).to.be.equal(ta
6ad0: 67 2e 69 74 65 6d 73 5b 32 5d 29 0a 0a 20 20 20  g.items[2])..   
6ae0: 20 74 61 67 2e 69 74 65 6d 73 2e 73 70 6c 69 63   tag.items.splic
6af0: 65 28 31 2c 20 31 29 0a 20 20 20 20 74 61 67 2e  e(1, 1).    tag.
6b00: 75 70 64 61 74 65 28 29 0a 20 20 20 20 65 78 70  update().    exp
6b10: 65 63 74 28 74 61 67 2e 72 6f 6f 74 2e 67 65 74  ect(tag.root.get
6b20: 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d  ElementsByTagNam
6b30: 65 28 27 64 69 76 27 29 2e 6c 65 6e 67 74 68 29  e('div').length)
6b40: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 32 29 0a  .to.be.equal(2).
6b50: 0a 20 20 20 20 74 61 67 2e 69 74 65 6d 73 2e 70  .    tag.items.p
6b60: 75 73 68 28 27 61 63 74 69 76 65 27 29 0a 20 20  ush('active').  
6b70: 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a 20    tag.update(). 
6b80: 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 72 6f     expect(tag.ro
6b90: 6f 74 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79  ot.getElementsBy
6ba0: 54 61 67 4e 61 6d 65 28 27 64 69 76 27 29 2e 6c  TagName('div').l
6bb0: 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75  ength).to.be.equ
6bc0: 61 6c 28 33 29 0a 20 20 20 20 65 78 70 65 63 74  al(3).    expect
6bd0: 28 74 61 67 2e 72 6f 6f 74 2e 67 65 74 45 6c 65  (tag.root.getEle
6be0: 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65 28 27  mentsByTagName('
6bf0: 64 69 76 27 29 5b 32 5d 2e 69 6e 6e 65 72 48 54  div')[2].innerHT
6c00: 4d 4c 29 2e 74 6f 2e 63 6f 6e 74 61 69 6e 28 27  ML).to.contain('
6c10: 61 63 74 69 76 65 27 29 0a 20 20 20 20 65 78 70  active').    exp
6c20: 65 63 74 28 74 61 67 2e 72 6f 6f 74 2e 67 65 74  ect(tag.root.get
6c30: 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d  ElementsByTagNam
6c40: 65 28 27 64 69 76 27 29 5b 32 5d 2e 63 6c 61 73  e('div')[2].clas
6c50: 73 4e 61 6d 65 29 2e 74 6f 2e 62 65 2e 65 71 75  sName).to.be.equ
6c60: 61 6c 28 27 61 63 74 69 76 65 27 29 0a 20 20 20  al('active').   
6c70: 20 65 78 70 65 63 74 28 74 61 67 2e 74 61 67 73   expect(tag.tags
6c80: 5b 27 6c 6f 6f 70 2d 69 6e 68 65 72 69 74 2d 69  ['loop-inherit-i
6c90: 74 65 6d 27 5d 5b 31 5d 2e 6f 70 74 73 2e 6e 61  tem'][1].opts.na
6ca0: 6d 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  me).to.be.equal(
6cb0: 74 61 67 2e 69 74 65 6d 73 5b 30 5d 29 0a 20 20  tag.items[0]).  
6cc0: 20 20 65 78 70 65 63 74 28 74 61 67 2e 74 61 67    expect(tag.tag
6cd0: 73 5b 27 6c 6f 6f 70 2d 69 6e 68 65 72 69 74 2d  s['loop-inherit-
6ce0: 69 74 65 6d 27 5d 5b 32 5d 2e 6f 70 74 73 2e 6e  item'][2].opts.n
6cf0: 61 6d 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  ame).to.be.equal
6d00: 28 74 61 67 2e 69 74 65 6d 73 5b 31 5d 29 0a 20  (tag.items[1]). 
6d10: 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 74 61     expect(tag.ta
6d20: 67 73 5b 27 6c 6f 6f 70 2d 69 6e 68 65 72 69 74  gs['loop-inherit
6d30: 2d 69 74 65 6d 27 5d 2e 6c 65 6e 67 74 68 29 2e  -item'].length).
6d40: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 34 29 0a 0a  to.be.equal(4)..
6d50: 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28      tag.unmount(
6d60: 29 0a 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 74  )..  })..  it('t
6d70: 68 65 20 44 4f 4d 20 65 76 65 6e 74 73 20 67 65  he DOM events ge
6d80: 74 20 65 78 65 63 75 74 65 64 20 69 6e 20 74 68  t executed in th
6d90: 65 20 72 69 67 68 74 20 63 6f 6e 74 65 78 74 27  e right context'
6da0: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20  , function() {. 
6db0: 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c     injectHTML('<
6dc0: 6c 6f 6f 70 2d 69 6e 68 65 72 69 74 3e 3c 2f 6c  loop-inherit></l
6dd0: 6f 6f 70 2d 69 6e 68 65 72 69 74 3e 27 29 0a 20  oop-inherit>'). 
6de0: 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d 20 72     const tag = r
6df0: 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d  iot.mount('loop-
6e00: 69 6e 68 65 72 69 74 27 29 5b 30 5d 0a 20 20 20  inherit')[0].   
6e10: 20 66 69 72 65 45 76 65 6e 74 28 74 61 67 2e 74   fireEvent(tag.t
6e20: 61 67 73 5b 27 6c 6f 6f 70 2d 69 6e 68 65 72 69  ags['loop-inheri
6e30: 74 2d 69 74 65 6d 27 5d 5b 30 5d 2e 72 6f 6f 74  t-item'][0].root
6e40: 2c 20 27 6d 6f 75 73 65 65 6e 74 65 72 27 29 0a  , 'mouseenter').
6e50: 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 77      expect(tag.w
6e60: 61 73 48 6f 76 65 72 65 64 29 2e 74 6f 2e 62 65  asHovered).to.be
6e70: 2e 65 71 75 61 6c 28 74 72 75 65 29 0a 20 20 20  .equal(true).   
6e80: 20 65 78 70 65 63 74 28 74 61 67 2e 72 6f 6f 74   expect(tag.root
6e90: 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61  .getElementsByTa
6ea0: 67 4e 61 6d 65 28 27 64 69 76 27 29 2e 6c 65 6e  gName('div').len
6eb0: 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  gth).to.be.equal
6ec0: 28 34 29 0a 20 20 20 20 66 69 72 65 45 76 65 6e  (4).    fireEven
6ed0: 74 28 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70  t(tag.tags['loop
6ee0: 2d 69 6e 68 65 72 69 74 2d 69 74 65 6d 27 5d 5b  -inherit-item'][
6ef0: 30 5d 2e 72 6f 6f 74 2c 20 27 63 6c 69 63 6b 27  0].root, 'click'
6f00: 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67  ).    expect(tag
6f10: 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 69 6e 68 65  .tags['loop-inhe
6f20: 72 69 74 2d 69 74 65 6d 27 5d 5b 30 5d 2e 77 61  rit-item'][0].wa
6f30: 73 43 6c 69 63 6b 65 64 29 2e 74 6f 2e 62 65 2e  sClicked).to.be.
6f40: 65 71 75 61 6c 28 74 72 75 65 29 0a 0a 20 20 20  equal(true)..   
6f50: 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20   tag.unmount(). 
6f60: 20 7d 29 0a 0a 20 20 69 74 28 27 6c 6f 6f 70 73   })..  it('loops
6f70: 20 6f 76 65 72 20 6f 74 68 65 72 20 74 61 67 20   over other tag 
6f80: 69 6e 73 74 61 6e 63 65 73 20 64 6f 20 6e 6f 74  instances do not
6f90: 20 6f 76 65 72 72 69 64 65 20 74 68 65 69 72 20   override their 
6fa0: 69 6e 74 65 72 6e 61 6c 20 70 72 6f 70 65 72 74  internal propert
6fb0: 69 65 73 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29  ies', function()
6fc0: 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d   {.    injectHTM
6fd0: 4c 28 27 3c 6c 6f 6f 70 2d 74 61 67 2d 69 6e 73  L('<loop-tag-ins
6fe0: 74 61 6e 63 65 73 3e 3c 2f 6c 6f 6f 70 2d 74 61  tances></loop-ta
6ff0: 67 2d 69 6e 73 74 61 6e 63 65 73 3e 27 29 0a 20  g-instances>'). 
7000: 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d 20 72     const tag = r
7010: 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d  iot.mount('loop-
7020: 74 61 67 2d 69 6e 73 74 61 6e 63 65 73 27 29 5b  tag-instances')[
7030: 30 5d 0a 0a 20 20 20 20 74 61 67 2e 73 74 61 72  0]..    tag.star
7040: 74 28 29 0a 0a 20 20 20 20 65 78 70 65 63 74 28  t()..    expect(
7050: 74 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 74  tag.tags['loop-t
7060: 61 67 2d 69 6e 73 74 61 6e 63 65 73 2d 63 68 69  ag-instances-chi
7070: 6c 64 27 5d 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e  ld'].length).to.
7080: 62 65 2e 65 71 75 61 6c 28 35 29 0a 20 20 20 20  be.equal(5).    
7090: 65 78 70 65 63 74 28 74 61 67 2e 74 61 67 73 5b  expect(tag.tags[
70a0: 27 6c 6f 6f 70 2d 74 61 67 2d 69 6e 73 74 61 6e  'loop-tag-instan
70b0: 63 65 73 2d 63 68 69 6c 64 27 5d 5b 30 5d 2e 72  ces-child'][0].r
70c0: 6f 6f 74 2e 74 61 67 4e 61 6d 65 2e 74 6f 4c 6f  oot.tagName.toLo
70d0: 77 65 72 43 61 73 65 28 29 29 2e 74 6f 2e 62 65  werCase()).to.be
70e0: 2e 65 71 75 61 6c 28 27 6c 6f 6f 70 2d 74 61 67  .equal('loop-tag
70f0: 2d 69 6e 73 74 61 6e 63 65 73 2d 63 68 69 6c 64  -instances-child
7100: 27 29 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74  ').    tag.updat
7110: 65 28 29 0a 20 20 20 20 65 78 70 65 63 74 28 74  e().    expect(t
7120: 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 74 61  ag.tags['loop-ta
7130: 67 2d 69 6e 73 74 61 6e 63 65 73 2d 63 68 69 6c  g-instances-chil
7140: 64 27 5d 5b 33 5d 2e 72 6f 6f 74 2e 74 61 67 4e  d'][3].root.tagN
7150: 61 6d 65 2e 74 6f 4c 6f 77 65 72 43 61 73 65 28  ame.toLowerCase(
7160: 29 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  )).to.be.equal('
7170: 6c 6f 6f 70 2d 74 61 67 2d 69 6e 73 74 61 6e 63  loop-tag-instanc
7180: 65 73 2d 63 68 69 6c 64 27 29 0a 0a 20 20 20 20  es-child')..    
7190: 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 0a 20  tag.unmount().. 
71a0: 20 7d 29 0a 0a 0a 20 20 69 74 28 27 6e 65 73 74   })...  it('nest
71b0: 65 64 20 6c 6f 6f 70 73 20 75 73 69 6e 67 20 6e  ed loops using n
71c0: 6f 6e 20 6f 62 6a 65 63 74 20 64 61 74 61 20 67  on object data g
71d0: 65 74 20 63 6f 72 72 65 63 74 6c 79 20 72 65 6e  et correctly ren
71e0: 64 65 72 65 64 27 2c 20 66 75 6e 63 74 69 6f 6e  dered', function
71f0: 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48  () {.    injectH
7200: 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 6e 65 73 74 65  TML('<loop-neste
7210: 64 2d 73 74 72 69 6e 67 73 2d 61 72 72 61 79 3e  d-strings-array>
7220: 3c 2f 6c 6f 6f 70 2d 6e 65 73 74 65 64 2d 73 74  </loop-nested-st
7230: 72 69 6e 67 73 2d 61 72 72 61 79 3e 27 29 0a 20  rings-array>'). 
7240: 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d 20 72     const tag = r
7250: 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d  iot.mount('loop-
7260: 6e 65 73 74 65 64 2d 73 74 72 69 6e 67 73 2d 61  nested-strings-a
7270: 72 72 61 79 27 29 5b 30 5d 0a 20 20 20 20 6c 65  rray')[0].    le
7280: 74 20 63 68 69 6c 64 72 65 6e 20 3d 20 24 24 28  t children = $$(
7290: 27 6c 6f 6f 70 2d 6e 65 73 74 65 64 2d 73 74 72  'loop-nested-str
72a0: 69 6e 67 73 2d 61 72 72 61 79 2d 69 74 65 6d 27  ings-array-item'
72b0: 2c 20 74 61 67 2e 72 6f 6f 74 29 0a 20 20 20 20  , tag.root).    
72c0: 65 78 70 65 63 74 28 63 68 69 6c 64 72 65 6e 2e  expect(children.
72d0: 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71  length).to.be.eq
72e0: 75 61 6c 28 34 29 0a 20 20 20 20 63 68 69 6c 64  ual(4).    child
72f0: 72 65 6e 20 3d 20 24 24 28 27 6c 6f 6f 70 2d 6e  ren = $$('loop-n
7300: 65 73 74 65 64 2d 73 74 72 69 6e 67 73 2d 61 72  ested-strings-ar
7310: 72 61 79 2d 69 74 65 6d 27 2c 20 74 61 67 2e 72  ray-item', tag.r
7320: 6f 6f 74 29 0a 20 20 20 20 66 69 72 65 45 76 65  oot).    fireEve
7330: 6e 74 28 63 68 69 6c 64 72 65 6e 5b 30 5d 2c 20  nt(children[0], 
7340: 27 63 6c 69 63 6b 27 29 0a 20 20 20 20 65 78 70  'click').    exp
7350: 65 63 74 28 63 68 69 6c 64 72 65 6e 2e 6c 65 6e  ect(children.len
7360: 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  gth).to.be.equal
7370: 28 34 29 0a 20 20 20 20 65 78 70 65 63 74 28 6e  (4).    expect(n
7380: 6f 72 6d 61 6c 69 7a 65 48 54 4d 4c 28 63 68 69  ormalizeHTML(chi
7390: 6c 64 72 65 6e 5b 30 5d 2e 69 6e 6e 65 72 48 54  ldren[0].innerHT
73a0: 4d 4c 29 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  ML)).to.be.equal
73b0: 28 27 3c 70 3e 62 3c 2f 70 3e 27 29 0a 20 20 20  ('<p>b</p>').   
73c0: 20 65 78 70 65 63 74 28 6e 6f 72 6d 61 6c 69 7a   expect(normaliz
73d0: 65 48 54 4d 4c 28 63 68 69 6c 64 72 65 6e 5b 31  eHTML(children[1
73e0: 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29 29 2e 74 6f  ].innerHTML)).to
73f0: 2e 62 65 2e 65 71 75 61 6c 28 27 3c 70 3e 61 3c  .be.equal('<p>a<
7400: 2f 70 3e 27 29 0a 20 20 20 20 74 61 67 2e 75 6e  /p>').    tag.un
7410: 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 0a 20  mount().  })... 
7420: 20 69 74 28 27 61 6e 79 20 44 4f 4d 20 65 76 65   it('any DOM eve
7430: 6e 74 20 69 6e 20 61 20 6c 6f 6f 70 20 75 70 64  nt in a loop upd
7440: 61 74 65 73 20 74 68 65 20 77 68 6f 6c 65 20 70  ates the whole p
7450: 61 72 65 6e 74 20 74 61 67 27 2c 20 66 75 6e 63  arent tag', func
7460: 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 69 6e 6a  tion() {.    inj
7470: 65 63 74 48 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 6e  ectHTML('<loop-n
7480: 75 6d 62 65 72 73 2d 6e 65 73 74 65 64 3e 3c 2f  umbers-nested></
7490: 6c 6f 6f 70 2d 6e 75 6d 62 65 72 73 2d 6e 65 73  loop-numbers-nes
74a0: 74 65 64 3e 27 29 0a 20 20 20 20 63 6f 6e 73 74  ted>').    const
74b0: 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e   tag = riot.moun
74c0: 74 28 27 6c 6f 6f 70 2d 6e 75 6d 62 65 72 73 2d  t('loop-numbers-
74d0: 6e 65 73 74 65 64 27 29 5b 30 5d 0a 20 20 20 20  nested')[0].    
74e0: 65 78 70 65 63 74 28 74 61 67 2e 72 6f 6f 74 2e  expect(tag.root.
74f0: 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61 67  getElementsByTag
7500: 4e 61 6d 65 28 27 75 6c 27 29 5b 30 5d 2e 67 65  Name('ul')[0].ge
7510: 74 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61  tElementsByTagNa
7520: 6d 65 28 27 6c 69 27 29 2e 6c 65 6e 67 74 68 29  me('li').length)
7530: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 34 29 0a  .to.be.equal(4).
7540: 20 20 20 20 66 69 72 65 45 76 65 6e 74 28 74 61      fireEvent(ta
7550: 67 2e 72 6f 6f 74 2e 67 65 74 45 6c 65 6d 65 6e  g.root.getElemen
7560: 74 73 42 79 54 61 67 4e 61 6d 65 28 27 75 6c 27  tsByTagName('ul'
7570: 29 5b 30 5d 2e 67 65 74 45 6c 65 6d 65 6e 74 73  )[0].getElements
7580: 42 79 54 61 67 4e 61 6d 65 28 27 6c 69 27 29 5b  ByTagName('li')[
7590: 30 5d 2c 20 27 63 6c 69 63 6b 27 29 0a 20 20 20  0], 'click').   
75a0: 20 65 78 70 65 63 74 28 74 61 67 2e 72 6f 6f 74   expect(tag.root
75b0: 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61  .getElementsByTa
75c0: 67 4e 61 6d 65 28 27 75 6c 27 29 5b 30 5d 2e 67  gName('ul')[0].g
75d0: 65 74 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e  etElementsByTagN
75e0: 61 6d 65 28 27 6c 69 27 29 2e 6c 65 6e 67 74 68  ame('li').length
75f0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 32 29  ).to.be.equal(2)
7600: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
7610: 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 72  ().  })..  it('r
7620: 69 6f 74 2e 6f 62 73 65 72 76 61 62 6c 65 20 69  iot.observable i
7630: 6e 73 74 61 6e 63 65 73 20 63 6f 75 6c 64 20 62  nstances could b
7640: 65 20 61 6c 73 6f 20 75 73 65 64 20 69 6e 20 61  e also used in a
7650: 20 6c 6f 6f 70 27 2c 20 66 75 6e 63 74 69 6f 6e   loop', function
7660: 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48  () {.    injectH
7670: 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 63 68 69 6c 64  TML('<loop-child
7680: 3e 3c 2f 6c 6f 6f 70 2d 63 68 69 6c 64 3e 27 29  ></loop-child>')
7690: 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d  .    const tag =
76a0: 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f   riot.mount('loo
76b0: 70 2d 63 68 69 6c 64 27 29 5b 30 5d 0a 0a 20 20  p-child')[0]..  
76c0: 20 20 74 61 67 2e 69 74 65 6d 73 20 3d 20 5b 72    tag.items = [r
76d0: 69 6f 74 2e 6f 62 73 65 72 76 61 62 6c 65 28 7b  iot.observable({
76e0: 6e 61 6d 65 3a 20 31 7d 29 2c 20 7b 6e 61 6d 65  name: 1}), {name
76f0: 3a 20 32 7d 5d 0a 20 20 20 20 74 61 67 2e 75 70  : 2}].    tag.up
7700: 64 61 74 65 28 29 0a 20 20 20 20 74 61 67 2e 69  date().    tag.i
7710: 74 65 6d 73 20 3d 20 5b 7b 6e 61 6d 65 3a 20 32  tems = [{name: 2
7720: 7d 5d 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74  }].    tag.updat
7730: 65 28 29 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d  e()..    tag.unm
7740: 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69  ount().  })..  i
7750: 74 28 27 74 68 65 20 75 70 64 61 74 65 20 65 76  t('the update ev
7760: 65 6e 74 20 72 65 74 75 72 6e 73 20 74 68 65 20  ent returns the 
7770: 74 61 67 20 69 6e 73 74 61 6e 63 65 27 2c 20 66  tag instance', f
7780: 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20  unction() {.    
7790: 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6c 6f 6f  injectHTML('<loo
77a0: 70 2d 63 68 69 6c 64 3e 3c 2f 6c 6f 6f 70 2d 63  p-child></loop-c
77b0: 68 69 6c 64 3e 27 29 0a 20 20 20 20 63 6f 6e 73  hild>').    cons
77c0: 74 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75  t tag = riot.mou
77d0: 6e 74 28 27 6c 6f 6f 70 2d 63 68 69 6c 64 27 29  nt('loop-child')
77e0: 5b 30 5d 0a 20 20 20 20 65 78 70 65 63 74 28 74  [0].    expect(t
77f0: 61 67 2e 75 70 64 61 74 65 28 29 29 2e 74 6f 2e  ag.update()).to.
7800: 6e 6f 74 2e 62 65 2e 65 71 75 61 6c 28 75 6e 64  not.be.equal(und
7810: 65 66 69 6e 65 64 29 0a 20 20 20 20 74 61 67 2e  efined).    tag.
7820: 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a  unmount().  })..
7830: 0a 20 20 69 74 28 27 74 61 62 6c 65 20 77 69 74  .  it('table wit
7840: 68 20 6d 75 6c 74 69 70 6c 65 20 62 6f 64 69 65  h multiple bodie
7850: 73 20 61 6e 64 20 64 79 6e 61 6d 69 63 20 73 74  s and dynamic st
7860: 79 6c 65 73 20 23 31 30 35 32 27 2c 20 66 75 6e  yles #1052', fun
7870: 63 74 69 6f 6e 28 29 20 7b 0a 0a 20 20 20 20 69  ction() {..    i
7880: 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 74 61 62 6c  njectHTML('<tabl
7890: 65 2d 6d 75 6c 74 69 62 6f 64 79 3e 3c 2f 74 61  e-multibody></ta
78a0: 62 6c 65 2d 6d 75 6c 74 69 62 6f 64 79 3e 27 29  ble-multibody>')
78b0: 0a 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20  ..    const tag 
78c0: 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 74 61  = riot.mount('ta
78d0: 62 6c 65 2d 6d 75 6c 74 69 62 6f 64 79 27 29 5b  ble-multibody')[
78e0: 30 5d 2c 0a 20 20 20 20 20 20 62 6f 64 69 65 73  0],.      bodies
78f0: 20 3d 20 24 24 28 27 74 62 6f 64 79 27 2c 20 74   = $$('tbody', t
7900: 61 67 2e 72 6f 6f 74 29 0a 0a 20 20 20 20 65 78  ag.root)..    ex
7910: 70 65 63 74 28 62 6f 64 69 65 73 2e 6c 65 6e 67  pect(bodies.leng
7920: 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  th).to.be.equal(
7930: 33 29 0a 20 20 20 20 66 6f 72 20 28 76 61 72 20  3).    for (var 
7940: 69 20 3d 20 30 3b 20 69 20 3c 20 62 6f 64 69 65  i = 0; i < bodie
7950: 73 2e 6c 65 6e 67 74 68 3b 20 2b 2b 69 29 20 7b  s.length; ++i) {
7960: 0a 20 20 20 20 20 20 65 78 70 65 63 74 28 6e 6f  .      expect(no
7970: 72 6d 61 6c 69 7a 65 48 54 4d 4c 28 62 6f 64 69  rmalizeHTML(bodi
7980: 65 73 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29  es[0].innerHTML)
7990: 29 0a 20 20 20 20 20 20 20 20 2e 74 6f 2e 6d 61  ).        .to.ma
79a0: 74 63 68 28 2f 3c 74 72 20 73 74 79 6c 65 3d 22  tch(/<tr style="
79b0: 62 61 63 6b 67 72 6f 75 6e 64 2d 63 6f 6c 6f 72  background-color
79c0: 3a 20 3f 28 3f 3a 77 68 69 74 65 7c 6c 69 6d 65  : ?(?:white|lime
79d0: 29 3b 3f 22 5b 5e 3e 5d 2a 3e 28 3f 3a 3c 74 64  );?"[^>]*>(?:<td
79e0: 5b 5e 3e 5d 2a 3e 5b 41 2d 43 5d 5c 64 3c 5c 2f  [^>]*>[A-C]\d<\/
79f0: 74 64 3e 29 7b 33 7d 3c 5c 2f 74 72 3e 2f 29 0a  td>){3}<\/tr>/).
7a00: 20 20 20 20 7d 0a 0a 20 20 20 20 65 78 70 65 63      }..    expec
7a10: 74 28 62 6f 64 69 65 73 5b 30 5d 2e 67 65 74 45  t(bodies[0].getE
7a20: 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65  lementsByTagName
7a30: 28 27 74 72 27 29 5b 30 5d 2e 73 74 79 6c 65 2e  ('tr')[0].style.
7a40: 62 61 63 6b 67 72 6f 75 6e 64 43 6f 6c 6f 72 29  backgroundColor)
7a50: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 77 68  .to.be.equal('wh
7a60: 69 74 65 27 29 0a 20 20 20 20 66 69 72 65 45 76  ite').    fireEv
7a70: 65 6e 74 28 74 61 67 2e 72 6f 6f 74 2e 67 65 74  ent(tag.root.get
7a80: 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d  ElementsByTagNam
7a90: 65 28 27 62 75 74 74 6f 6e 27 29 5b 30 5d 2c 20  e('button')[0], 
7aa0: 27 63 6c 69 63 6b 27 29 0a 20 20 20 20 65 78 70  'click').    exp
7ab0: 65 63 74 28 62 6f 64 69 65 73 5b 30 5d 2e 67 65  ect(bodies[0].ge
7ac0: 74 45 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61  tElementsByTagNa
7ad0: 6d 65 28 27 74 72 27 29 5b 30 5d 2e 73 74 79 6c  me('tr')[0].styl
7ae0: 65 2e 62 61 63 6b 67 72 6f 75 6e 64 43 6f 6c 6f  e.backgroundColo
7af0: 72 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  r).to.be.equal('
7b00: 6c 69 6d 65 27 29 0a 0a 20 20 20 20 74 61 67 2e  lime')..    tag.
7b10: 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a  unmount().  })..
7b20: 20 20 69 74 28 27 74 61 62 6c 65 20 77 69 74 68    it('table with
7b30: 20 74 62 6f 64 79 20 61 6e 64 20 74 68 65 61 64   tbody and thead
7b40: 20 23 31 35 34 39 27 2c 20 66 75 6e 63 74 69 6f   #1549', functio
7b50: 6e 28 29 20 7b 0a 0a 20 20 20 20 69 6e 6a 65 63  n() {..    injec
7b60: 74 48 54 4d 4c 28 27 3c 74 61 62 6c 65 2d 74 68  tHTML('<table-th
7b70: 65 61 64 2d 74 66 6f 6f 74 2d 6e 65 73 74 65 64  ead-tfoot-nested
7b80: 3e 3c 2f 74 61 62 6c 65 2d 74 68 65 61 64 2d 74  ></table-thead-t
7b90: 66 6f 6f 74 2d 6e 65 73 74 65 64 3e 27 29 0a 0a  foot-nested>')..
7ba0: 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d 20      const tag = 
7bb0: 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 74 61 62 6c  riot.mount('tabl
7bc0: 65 2d 74 68 65 61 64 2d 74 66 6f 6f 74 2d 6e 65  e-thead-tfoot-ne
7bd0: 73 74 65 64 27 29 5b 30 5d 2c 0a 20 20 20 20 20  sted')[0],.     
7be0: 20 62 6f 64 69 65 73 20 3d 20 24 24 28 27 74 62   bodies = $$('tb
7bf0: 6f 64 79 27 2c 20 74 61 67 2e 72 6f 6f 74 29 2c  ody', tag.root),
7c00: 0a 20 20 20 20 20 20 68 65 61 64 73 20 3d 20 24  .      heads = $
7c10: 24 28 27 74 68 65 61 64 27 2c 20 74 61 67 2e 72  $('thead', tag.r
7c20: 6f 6f 74 29 2c 0a 20 20 20 20 20 20 66 6f 6f 74  oot),.      foot
7c30: 73 20 3d 20 24 24 28 27 74 66 6f 6f 74 27 2c 20  s = $$('tfoot', 
7c40: 74 61 67 2e 72 6f 6f 74 29 0a 0a 20 20 20 20 65  tag.root)..    e
7c50: 78 70 65 63 74 28 62 6f 64 69 65 73 2e 6c 65 6e  xpect(bodies.len
7c60: 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  gth).to.be.equal
7c70: 28 31 29 0a 20 20 20 20 65 78 70 65 63 74 28 68  (1).    expect(h
7c80: 65 61 64 73 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e  eads.length).to.
7c90: 62 65 2e 65 71 75 61 6c 28 31 29 0a 20 20 20 20  be.equal(1).    
7ca0: 65 78 70 65 63 74 28 66 6f 6f 74 73 2e 6c 65 6e  expect(foots.len
7cb0: 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  gth).to.be.equal
7cc0: 28 31 29 0a 0a 20 20 20 20 76 61 72 20 74 68 73  (1)..    var ths
7cd0: 20 3d 20 24 24 28 27 74 68 27 2c 20 74 61 67 2e   = $$('th', tag.
7ce0: 72 6f 6f 74 29 2c 0a 20 20 20 20 20 20 74 72 73  root),.      trs
7cf0: 20 3d 20 24 24 28 27 74 72 27 2c 20 74 61 67 2e   = $$('tr', tag.
7d00: 72 6f 6f 74 29 2c 0a 20 20 20 20 20 20 74 64 73  root),.      tds
7d10: 20 3d 20 24 24 28 27 74 64 27 2c 20 74 61 67 2e   = $$('td', tag.
7d20: 72 6f 6f 74 29 0a 0a 20 20 20 20 65 78 70 65 63  root)..    expec
7d30: 74 28 74 68 73 2e 6c 65 6e 67 74 68 29 2e 74 6f  t(ths.length).to
7d40: 2e 62 65 2e 65 71 75 61 6c 28 33 29 0a 20 20 20  .be.equal(3).   
7d50: 20 65 78 70 65 63 74 28 74 72 73 2e 6c 65 6e 67   expect(trs.leng
7d60: 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  th).to.be.equal(
7d70: 35 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 64  5).    expect(td
7d80: 73 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e  s.length).to.be.
7d90: 65 71 75 61 6c 28 36 29 0a 0a 20 20 20 20 74 61  equal(6)..    ta
7da0: 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29  g.unmount().  })
7db0: 0a 0a 20 20 69 74 28 27 74 61 62 6c 65 20 77 69  ..  it('table wi
7dc0: 74 68 20 63 61 70 74 69 6f 6e 20 61 6e 64 20 6c  th caption and l
7dd0: 6f 6f 70 65 64 20 63 6f 6c 73 2c 20 74 68 73 2c  ooped cols, ths,
7de0: 20 61 6e 64 20 74 72 73 20 23 31 30 36 37 27 2c   and trs #1067',
7df0: 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20   function() {.  
7e00: 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6c    injectHTML('<l
7e10: 6f 6f 70 2d 63 6f 6c 73 3e 3c 2f 6c 6f 6f 70 2d  oop-cols></loop-
7e20: 63 6f 6c 73 3e 27 29 0a 20 20 20 20 76 61 72 20  cols>').    var 
7e30: 64 61 74 61 20 3d 20 7b 0a 20 20 20 20 20 20 2f  data = {.      /
7e40: 2f 20 63 6f 70 69 65 64 20 66 72 6f 6d 20 6c 6f  / copied from lo
7e50: 6f 70 2d 63 6f 6c 73 2e 74 61 67 0a 20 20 20 20  op-cols.tag.    
7e60: 20 20 68 65 61 64 65 72 73 3a 20 5b 0a 20 20 20    headers: [.   
7e70: 20 20 20 20 20 27 4e 61 6d 65 27 2c 0a 20 20 20       'Name',.   
7e80: 20 20 20 20 20 27 4e 75 6d 62 65 72 27 2c 0a 20       'Number',. 
7e90: 20 20 20 20 20 20 20 27 41 64 64 72 65 73 73 27         'Address'
7ea0: 2c 0a 20 20 20 20 20 20 20 20 27 43 69 74 79 27  ,.        'City'
7eb0: 2c 0a 20 20 20 20 20 20 20 20 27 43 6f 6e 74 61  ,.        'Conta
7ec0: 63 74 27 0a 20 20 20 20 20 20 5d 2c 0a 20 20 20  ct'.      ],.   
7ed0: 20 20 20 64 61 74 61 3a 20 5b 0a 20 20 20 20 20     data: [.     
7ee0: 20 20 20 5b 27 41 62 63 27 2c 20 27 31 30 27 2c     ['Abc', '10',
7ef0: 20 27 41 20 34 42 27 2c 20 27 4d c3 a9 78 69 63   'A 4B', 'M..xic
7f00: 6f 27 2c 20 27 4a 75 61 6e 27 5d 2c 0a 20 20 20  o', 'Juan'],.   
7f10: 20 20 20 20 20 5b 27 44 65 66 27 2c 20 27 32 30       ['Def', '20
7f20: 27 2c 20 27 42 20 35 30 27 2c 20 27 55 53 41 27  ', 'B 50', 'USA'
7f30: 2c 20 27 41 6e 6e 61 27 5d 2c 0a 20 20 20 20 20  , 'Anna'],.     
7f40: 20 20 20 5b 27 47 68 69 27 2c 20 27 33 30 27 2c     ['Ghi', '30',
7f50: 20 27 44 20 36 30 27 2c 20 27 4a 61 70 61 6e 27   'D 60', 'Japan'
7f60: 2c 20 27 27 5d 2c 0a 20 20 20 20 20 20 20 20 5b  , ''],.        [
7f70: 27 4a 6b 6c 27 2c 20 27 34 30 27 2c 20 27 45 20  'Jkl', '40', 'E 
7f80: 31 43 27 2c 20 27 46 72 61 6e 63 65 27 2c 20 27  1C', 'France', '
7f90: 42 61 6c 62 69 6e 61 27 5d 0a 20 20 20 20 20 20  Balbina'].      
7fa0: 5d 0a 20 20 20 20 7d 0a 20 20 20 20 63 6f 6e 73  ].    }.    cons
7fb0: 74 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75  t tag = riot.mou
7fc0: 6e 74 28 27 6c 6f 6f 70 2d 63 6f 6c 73 27 29 5b  nt('loop-cols')[
7fd0: 30 5d 0a 20 20 20 20 6c 65 74 20 65 6c 2c 20 69  0].    let el, i
7fe0: 2c 20 6b 0a 0a 20 20 20 20 74 61 67 2e 75 70 64  , k..    tag.upd
7ff0: 61 74 65 28 29 0a 0a 20 20 20 20 65 6c 20 3d 20  ate()..    el = 
8000: 67 65 74 45 6c 73 28 27 63 61 70 74 69 6f 6e 27  getEls('caption'
8010: 29 5b 30 5d 0a 20 20 20 20 65 78 70 65 63 74 28  )[0].    expect(
8020: 65 6c 2e 69 6e 6e 65 72 48 54 4d 4c 29 2e 74 6f  el.innerHTML).to
8030: 2e 62 65 2e 65 71 75 61 6c 28 27 4c 6f 6f 70 20  .be.equal('Loop 
8040: 43 6f 6c 73 27 29 0a 0a 20 20 20 20 65 6c 20 3d  Cols')..    el =
8050: 20 67 65 74 45 6c 73 28 27 63 6f 6c 67 72 6f 75   getEls('colgrou
8060: 70 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 65  p').    expect(e
8070: 6c 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e  l.length).to.be.
8080: 65 71 75 61 6c 28 31 29 0a 0a 20 20 20 20 65 6c  equal(1)..    el
8090: 20 3d 20 67 65 74 45 6c 73 28 27 63 6f 6c 27 2c   = getEls('col',
80a0: 20 65 6c 5b 30 5d 29 0a 20 20 20 20 65 78 70 65   el[0]).    expe
80b0: 63 74 28 65 6c 2e 6c 65 6e 67 74 68 29 2e 74 6f  ct(el.length).to
80c0: 2e 62 65 2e 65 71 75 61 6c 28 35 29 0a 0a 20 20  .be.equal(5)..  
80d0: 20 20 65 6c 20 3d 20 67 65 74 45 6c 73 28 27 74    el = getEls('t
80e0: 72 27 2c 20 67 65 74 45 6c 73 28 27 74 68 65 61  r', getEls('thea
80f0: 64 27 29 5b 30 5d 29 0a 20 20 20 20 65 78 70 65  d')[0]).    expe
8100: 63 74 28 65 6c 2e 6c 65 6e 67 74 68 29 2e 74 6f  ct(el.length).to
8110: 2e 62 65 2e 65 71 75 61 6c 28 31 29 0a 0a 20 20  .be.equal(1)..  
8120: 20 20 65 6c 20 3d 20 67 65 74 45 6c 73 28 27 74    el = getEls('t
8130: 68 27 2c 20 65 6c 5b 30 5d 29 0a 20 20 20 20 65  h', el[0]).    e
8140: 78 70 65 63 74 28 65 6c 2e 6c 65 6e 67 74 68 29  xpect(el.length)
8150: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 35 29 0a  .to.be.equal(5).
8160: 20 20 20 20 66 6f 72 20 28 69 20 3d 20 30 3b 20      for (i = 0; 
8170: 69 20 3c 20 65 6c 2e 6c 65 6e 67 74 68 3b 20 2b  i < el.length; +
8180: 2b 69 29 20 7b 0a 20 20 20 20 20 20 65 78 70 65  +i) {.      expe
8190: 63 74 28 65 6c 5b 69 5d 2e 74 61 67 4e 61 6d 65  ct(el[i].tagName
81a0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 54  ).to.be.equal('T
81b0: 48 27 29 0a 20 20 20 20 20 20 65 78 70 65 63 74  H').      expect
81c0: 28 65 6c 5b 69 5d 2e 69 6e 6e 65 72 48 54 4d 4c  (el[i].innerHTML
81d0: 2e 74 72 69 6d 28 29 29 2e 74 6f 2e 62 65 2e 65  .trim()).to.be.e
81e0: 71 75 61 6c 28 64 61 74 61 2e 68 65 61 64 65 72  qual(data.header
81f0: 73 5b 69 5d 29 0a 20 20 20 20 7d 0a 0a 20 20 20  s[i]).    }..   
8200: 20 65 6c 20 3d 20 67 65 74 45 6c 73 28 27 74 72   el = getEls('tr
8210: 27 2c 20 67 65 74 45 6c 73 28 27 74 62 6f 64 79  ', getEls('tbody
8220: 27 29 5b 30 5d 29 0a 20 20 20 20 65 78 70 65 63  ')[0]).    expec
8230: 74 28 65 6c 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e  t(el.length).to.
8240: 62 65 2e 65 71 75 61 6c 28 34 29 0a 20 20 20 20  be.equal(4).    
8250: 2f 2f 63 6f 6e 73 6f 6c 65 2e 6c 6f 67 28 27 20  //console.log(' 
8260: 2d 20 2d 20 2d 20 74 62 6f 64 79 2e 74 72 3a 20  - - - tbody.tr: 
8270: 27 20 2b 20 65 6c 5b 30 5d 2e 69 6e 6e 65 72 48  ' + el[0].innerH
8280: 54 4d 4c 29 0a 0a 20 20 20 20 66 6f 72 20 28 69  TML)..    for (i
8290: 20 3d 20 30 3b 20 69 20 3c 20 65 6c 2e 6c 65 6e   = 0; i < el.len
82a0: 67 74 68 3b 20 2b 2b 69 29 20 7b 0a 20 20 20 20  gth; ++i) {.    
82b0: 20 20 76 61 72 20 63 65 6c 6c 73 20 3d 20 67 65    var cells = ge
82c0: 74 45 6c 73 28 27 74 64 27 2c 20 65 6c 5b 69 5d  tEls('td', el[i]
82d0: 29 0a 20 20 20 20 20 20 65 78 70 65 63 74 28 63  ).      expect(c
82e0: 65 6c 6c 73 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e  ells.length).to.
82f0: 62 65 2e 65 71 75 61 6c 28 35 29 0a 20 20 20 20  be.equal(5).    
8300: 20 20 66 6f 72 20 28 6b 20 3d 20 30 3b 20 6b 20    for (k = 0; k 
8310: 3c 20 63 65 6c 6c 73 2e 6c 65 6e 67 74 68 3b 20  < cells.length; 
8320: 2b 2b 6b 29 20 7b 0a 20 20 20 20 20 20 20 20 2f  ++k) {.        /
8330: 2f 63 6f 6e 73 6f 6c 65 2e 6c 6f 67 28 27 20 2d  /console.log(' -
8340: 20 2d 20 2d 20 67 65 74 74 69 6e 67 20 64 61 74   - - getting dat
8350: 61 5b 27 20 2b 20 69 20 2b 20 27 2c 27 20 2b 20  a[' + i + ',' + 
8360: 6b 20 2b 20 27 5d 27 29 0a 20 20 20 20 20 20 20  k + ']').       
8370: 20 65 78 70 65 63 74 28 63 65 6c 6c 73 5b 6b 5d   expect(cells[k]
8380: 2e 74 61 67 4e 61 6d 65 29 2e 74 6f 2e 62 65 2e  .tagName).to.be.
8390: 65 71 75 61 6c 28 27 54 44 27 29 0a 20 20 20 20  equal('TD').    
83a0: 20 20 20 20 65 78 70 65 63 74 28 63 65 6c 6c 73      expect(cells
83b0: 5b 6b 5d 2e 69 6e 6e 65 72 48 54 4d 4c 2e 74 72  [k].innerHTML.tr
83c0: 69 6d 28 29 29 2e 74 6f 2e 62 65 2e 65 71 75 61  im()).to.be.equa
83d0: 6c 28 64 61 74 61 2e 64 61 74 61 5b 69 5d 5b 6b  l(data.data[i][k
83e0: 5d 29 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d  ]).      }.    }
83f0: 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e  ..    tag.unmoun
8400: 74 28 29 0a 0a 20 20 20 20 66 75 6e 63 74 69 6f  t()..    functio
8410: 6e 20 67 65 74 45 6c 73 28 74 2c 20 65 29 20 7b  n getEls(t, e) {
8420: 0a 20 20 20 20 20 20 69 66 20 28 21 65 29 20 65  .      if (!e) e
8430: 20 3d 20 74 61 67 2e 72 6f 6f 74 0a 20 20 20 20   = tag.root.    
8440: 20 20 72 65 74 75 72 6e 20 65 2e 67 65 74 45 6c    return e.getEl
8450: 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65 28  ementsByTagName(
8460: 74 29 0a 20 20 20 20 7d 0a 20 20 7d 29 0a 0a 0a  t).    }.  })...
8470: 0a 20 20 69 74 28 27 74 61 62 6c 65 2f 74 68 65  .  it('table/the
8480: 61 64 2f 74 62 6f 64 79 2f 74 66 6f 6f 74 20 75  ad/tbody/tfoot u
8490: 73 65 64 20 61 73 20 72 6f 6f 74 20 65 6c 65 6d  sed as root elem
84a0: 65 6e 74 20 6f 66 20 63 75 73 74 6f 6d 20 74 61  ent of custom ta
84b0: 67 73 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20  gs', function() 
84c0: 7b 0a 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d  {..    injectHTM
84d0: 4c 28 27 3c 74 61 62 6c 65 2d 74 65 73 74 3e 3c  L('<table-test><
84e0: 2f 74 61 62 6c 65 2d 74 65 73 74 3e 27 29 0a 20  /table-test>'). 
84f0: 20 20 20 76 61 72 0a 20 20 20 20 20 20 74 61 67     var.      tag
8500: 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 74   = riot.mount('t
8510: 61 62 6c 65 2d 74 65 73 74 27 29 5b 30 5d 2c 0a  able-test')[0],.
8520: 20 20 20 20 20 20 74 62 6c 0a 0a 20 20 20 20 2f        tbl..    /
8530: 2f 20 73 65 74 20 22 74 62 6c 22 20 74 6f 20 74  / set "tbl" to t
8540: 68 65 20 74 61 62 6c 65 2d 74 65 73 74 20 72 6f  he table-test ro
8550: 6f 74 20 65 6c 65 6d 65 6e 74 0a 20 20 20 20 65  ot element.    e
8560: 78 70 65 63 74 28 74 61 67 29 2e 74 6f 2e 6e 6f  xpect(tag).to.no
8570: 74 2e 62 65 2e 65 6d 70 74 79 0a 20 20 20 20 74  t.be.empty.    t
8580: 62 6c 20 3d 20 74 61 67 2e 72 6f 6f 74 0a 20 20  bl = tag.root.  
8590: 20 20 65 78 70 65 63 74 28 74 62 6c 29 2e 74 6f    expect(tbl).to
85a0: 2e 6e 6f 74 2e 62 65 2e 65 6d 70 74 79 0a 20 20  .not.be.empty.  
85b0: 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a 0a    tag.update()..
85c0: 20 20 20 20 74 65 73 74 54 61 62 6c 65 28 74 62      testTable(tb
85d0: 6c 2c 20 27 74 61 62 6c 65 2d 63 61 70 74 69 6f  l, 'table-captio
85e0: 6e 27 2c 20 7b 0a 20 20 20 20 20 20 74 62 6f 64  n', {.      tbod
85f0: 79 3a 20 31 2c 0a 20 20 20 20 20 20 63 61 70 74  y: 1,.      capt
8600: 69 6f 6e 3a 20 74 72 75 65 2c 0a 20 20 20 20 20  ion: true,.     
8610: 20 63 6f 6c 67 72 6f 75 70 3a 20 74 72 75 65 0a   colgroup: true.
8620: 20 20 20 20 7d 29 0a 20 20 20 20 74 65 73 74 54      }).    testT
8630: 61 62 6c 65 28 74 62 6c 2c 20 27 74 61 62 6c 65  able(tbl, 'table
8640: 2d 63 6f 6c 67 72 6f 75 70 27 2c 20 7b 0a 20 20  -colgroup', {.  
8650: 20 20 20 20 74 68 65 61 64 3a 20 31 2c 0a 20 20      thead: 1,.  
8660: 20 20 20 20 74 62 6f 64 79 3a 20 31 2c 0a 20 20      tbody: 1,.  
8670: 20 20 20 20 63 6f 6c 67 72 6f 75 70 3a 20 74 72      colgroup: tr
8680: 75 65 0a 20 20 20 20 7d 29 0a 20 20 20 20 74 65  ue.    }).    te
8690: 73 74 54 61 62 6c 65 28 74 62 6c 2c 20 27 74 61  stTable(tbl, 'ta
86a0: 62 6c 65 2d 6c 6f 6f 70 65 64 2d 63 6f 6c 27 2c  ble-looped-col',
86b0: 20 7b 0a 20 20 20 20 20 20 74 68 65 61 64 3a 20   {.      thead: 
86c0: 31 2c 0a 20 20 20 20 20 20 74 62 6f 64 79 3a 20  1,.      tbody: 
86d0: 31 2c 0a 20 20 20 20 20 20 63 6f 6c 3a 20 74 72  1,.      col: tr
86e0: 75 65 0a 20 20 20 20 7d 29 0a 20 20 20 20 74 65  ue.    }).    te
86f0: 73 74 54 61 62 6c 65 28 74 62 6c 2c 20 27 74 61  stTable(tbl, 'ta
8700: 62 6c 65 2d 6d 75 6c 74 69 2d 63 6f 6c 27 2c 20  ble-multi-col', 
8710: 7b 0a 20 20 20 20 20 20 74 68 65 61 64 3a 20 31  {.      thead: 1
8720: 2c 0a 20 20 20 20 20 20 74 62 6f 64 79 3a 20 31  ,.      tbody: 1
8730: 2c 0a 20 20 20 20 20 20 63 6f 6c 3a 20 74 72 75  ,.      col: tru
8740: 65 0a 20 20 20 20 7d 29 0a 20 20 20 20 74 65 73  e.    }).    tes
8750: 74 54 61 62 6c 65 28 74 62 6c 2c 20 27 74 61 62  tTable(tbl, 'tab
8760: 6c 65 2d 74 66 6f 6f 74 27 2c 20 7b 0a 20 20 20  le-tfoot', {.   
8770: 20 20 20 74 66 6f 6f 74 3a 20 31 2c 0a 20 20 20     tfoot: 1,.   
8780: 20 20 20 74 62 6f 64 79 3a 20 31 0a 20 20 20 20     tbody: 1.    
8790: 7d 29 0a 20 20 20 20 74 65 73 74 54 61 62 6c 65  }).    testTable
87a0: 28 74 62 6c 2c 20 27 74 61 62 6c 65 2d 74 72 2d  (tbl, 'table-tr-
87b0: 62 6f 64 79 2d 6f 6e 6c 79 27 2c 20 7b 0a 20 20  body-only', {.  
87c0: 20 20 20 20 74 72 3a 20 32 0a 20 20 20 20 7d 29      tr: 2.    })
87d0: 0a 20 20 20 20 74 65 73 74 54 61 62 6c 65 28 74  .    testTable(t
87e0: 62 6c 2c 20 27 74 61 62 6c 65 2d 74 72 2d 61 6c  bl, 'table-tr-al
87f0: 6f 6e 65 27 2c 20 7b 0a 20 20 20 20 20 20 74 72  one', {.      tr
8800: 3a 20 31 0a 20 20 20 20 7d 29 0a 20 20 20 20 74  : 1.    }).    t
8810: 65 73 74 54 61 62 6c 65 28 74 62 6c 2c 20 27 74  estTable(tbl, 't
8820: 61 62 6c 65 2d 63 75 73 74 6f 6d 2d 74 68 65 61  able-custom-thea
8830: 64 2d 74 66 6f 6f 74 27 2c 20 7b 0a 20 20 20 20  d-tfoot', {.    
8840: 20 20 74 68 65 61 64 3a 20 31 2c 0a 20 20 20 20    thead: 1,.    
8850: 20 20 74 66 6f 6f 74 3a 20 31 2c 0a 20 20 20 20    tfoot: 1,.    
8860: 20 20 74 62 6f 64 79 3a 20 32 2c 0a 20 20 20 20    tbody: 2,.    
8870: 20 20 63 6f 6c 67 72 6f 75 70 3a 20 74 72 75 65    colgroup: true
8880: 0a 20 20 20 20 7d 29 0a 0a 20 20 20 20 74 61 67  .    })..    tag
8890: 2e 75 6e 6d 6f 75 6e 74 28 29 0a 0a 20 20 20 20  .unmount()..    
88a0: 2f 2f 20 74 65 73 74 20 74 68 65 20 74 61 62 6c  // test the tabl
88b0: 65 20 61 6e 64 20 63 61 6c 6c 20 74 68 65 20 74  e and call the t
88c0: 65 73 74 73 20 66 6f 72 20 74 68 65 20 63 6f 6e  ests for the con
88d0: 74 65 6e 74 0a 20 20 20 20 66 75 6e 63 74 69 6f  tent.    functio
88e0: 6e 20 74 65 73 74 54 61 62 6c 65 28 72 6f 6f 74  n testTable(root
88f0: 2c 20 6e 61 6d 65 2c 20 69 6e 66 6f 29 20 7b 0a  , name, info) {.
8900: 20 20 20 20 20 20 76 61 72 20 73 2c 20 6b 65 79        var s, key
8910: 0a 0a 20 20 20 20 20 20 72 6f 6f 74 20 3d 20 24  ..      root = $
8920: 24 28 27 74 61 62 6c 65 5b 64 61 74 61 2d 69 73  $('table[data-is
8930: 3d 27 20 2b 20 6e 61 6d 65 20 2b 20 27 5d 27 2c  =' + name + ']',
8940: 20 72 6f 6f 74 29 0a 20 20 20 20 20 20 73 20 3d   root).      s =
8950: 20 6e 61 6d 65 20 2b 20 27 2e 6c 65 6e 67 74 68   name + '.length
8960: 3a 20 27 0a 20 20 20 20 20 20 65 78 70 65 63 74  : '.      expect
8970: 28 73 20 2b 20 72 6f 6f 74 2e 6c 65 6e 67 74 68  (s + root.length
8980: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 73 20  ).to.be.equal(s 
8990: 2b 20 27 31 27 29 0a 20 20 20 20 20 20 72 6f 6f  + '1').      roo
89a0: 74 20 3d 20 72 6f 6f 74 5b 30 5d 0a 0a 20 20 20  t = root[0]..   
89b0: 20 20 20 2f 2f 20 74 65 73 74 20 63 6f 6e 74 65     // test conte
89c0: 6e 74 0a 20 20 20 20 20 20 66 6f 72 20 28 6b 65  nt.      for (ke
89d0: 79 20 69 6e 20 69 6e 66 6f 29 20 7b 20 2f 2f 20  y in info) { // 
89e0: 65 73 6c 69 6e 74 2d 64 69 73 61 62 6c 65 2d 6c  eslint-disable-l
89f0: 69 6e 65 0a 20 20 20 20 20 20 20 20 69 66 20 28  ine.        if (
8a00: 69 6e 66 6f 5b 6b 65 79 5d 20 3d 3d 3d 20 74 72  info[key] === tr
8a10: 75 65 29 0a 20 20 20 20 20 20 20 20 20 20 74 65  ue).          te
8a20: 73 74 4f 74 68 65 72 28 72 6f 6f 74 2c 20 6b 65  stOther(root, ke
8a30: 79 29 0a 20 20 20 20 20 20 20 20 65 6c 73 65 0a  y).        else.
8a40: 20 20 20 20 20 20 20 20 20 20 74 65 73 74 52 6f            testRo
8a50: 77 73 28 72 6f 6f 74 2c 20 6b 65 79 2c 20 69 6e  ws(root, key, in
8a60: 66 6f 5b 6b 65 79 5d 29 0a 20 20 20 20 20 20 7d  fo[key]).      }
8a70: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2f 20 74  .    }..    // t
8a80: 65 73 74 20 72 6f 77 73 20 61 6e 64 20 63 65 6c  est rows and cel
8a90: 6c 73 20 66 6f 72 20 61 6e 20 65 6c 65 6d 65 6e  ls for an elemen
8aa0: 74 20 6f 66 20 74 68 65 61 64 2f 74 66 6f 6f 74  t of thead/tfoot
8ab0: 2f 74 62 6f 64 79 0a 20 20 20 20 66 75 6e 63 74  /tbody.    funct
8ac0: 69 6f 6e 20 74 65 73 74 52 6f 77 73 28 72 6f 6f  ion testRows(roo
8ad0: 74 2c 20 6e 61 6d 65 2c 20 63 6e 74 29 20 7b 0a  t, name, cnt) {.
8ae0: 20 20 20 20 20 20 76 61 72 20 73 2c 20 69 2c 20        var s, i, 
8af0: 72 2c 20 63 2c 20 72 6f 77 73 2c 20 63 65 6c 6c  r, c, rows, cell
8b00: 73 2c 20 74 65 6d 70 6c 0a 0a 20 20 20 20 20 20  s, templ..      
8b10: 2f 2f 20 63 68 65 63 6b 20 74 68 65 20 63 6f 75  // check the cou
8b20: 6e 74 20 6f 66 20 74 68 69 73 20 65 6c 65 6d 65  nt of this eleme
8b30: 6e 74 0a 20 20 20 20 20 20 72 6f 6f 74 20 3d 20  nt.      root = 
8b40: 72 6f 6f 74 2e 67 65 74 45 6c 65 6d 65 6e 74 73  root.getElements
8b50: 42 79 54 61 67 4e 61 6d 65 28 6e 61 6d 65 29 0a  ByTagName(name).
8b60: 20 20 20 20 20 20 73 20 3d 20 6e 61 6d 65 20 2b        s = name +
8b70: 20 27 2e 6c 65 6e 67 74 68 3a 20 27 0a 20 20 20   '.length: '.   
8b80: 20 20 20 65 78 70 65 63 74 28 73 20 2b 20 72 6f     expect(s + ro
8b90: 6f 74 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65  ot.length).to.be
8ba0: 2e 65 71 75 61 6c 28 73 20 2b 20 63 6e 74 29 0a  .equal(s + cnt).
8bb0: 20 20 20 20 20 20 69 66 20 28 6e 61 6d 65 20 3d        if (name =
8bc0: 3d 3d 20 27 74 72 27 29 20 7b 0a 20 20 20 20 20  == 'tr') {.     
8bd0: 20 20 20 6e 61 6d 65 20 3d 20 27 74 62 6f 64 79     name = 'tbody
8be0: 27 0a 20 20 20 20 20 20 20 20 72 6f 6f 74 20 3d  '.        root =
8bf0: 20 5b 7b 20 72 6f 77 73 3a 20 72 6f 6f 74 20 7d   [{ rows: root }
8c00: 5d 0a 20 20 20 20 20 20 20 20 2f 2f 2e 2e 2e 61  ].        //...a
8c10: 6e 64 20 6c 65 61 76 65 20 63 6e 74 20 61 73 2d  nd leave cnt as-
8c20: 69 73 2c 20 65 6c 73 65 20 61 64 6a 75 73 74 20  is, else adjust 
8c30: 63 6e 74 20 74 6f 20 65 78 70 65 63 74 65 64 20  cnt to expected 
8c40: 72 6f 77 73 0a 20 20 20 20 20 20 7d 20 65 6c 73  rows.      } els
8c50: 65 20 63 6e 74 20 3d 20 6e 61 6d 65 20 3d 3d 3d  e cnt = name ===
8c60: 20 27 74 62 6f 64 79 27 20 3f 20 32 20 3a 20 31   'tbody' ? 2 : 1
8c70: 0a 0a 20 20 20 20 20 20 2f 2f 20 63 68 65 63 6b  ..      // check
8c80: 20 65 61 63 68 20 65 6c 65 6d 65 6e 74 0a 20 20   each element.  
8c90: 20 20 20 20 66 6f 72 20 28 69 20 3d 20 30 3b 20      for (i = 0; 
8ca0: 69 20 3c 20 72 6f 6f 74 2e 6c 65 6e 67 74 68 3b  i < root.length;
8cb0: 20 69 2b 2b 29 20 7b 0a 20 20 20 20 20 20 20 20   i++) {.        
8cc0: 2f 2f 20 74 65 73 74 20 74 68 65 20 72 6f 77 73  // test the rows
8cd0: 0a 20 20 20 20 20 20 20 20 72 6f 77 73 20 3d 20  .        rows = 
8ce0: 72 6f 6f 74 5b 69 5d 2e 72 6f 77 73 0a 20 20 20  root[i].rows.   
8cf0: 20 20 20 20 20 65 78 70 65 63 74 28 72 6f 77 73       expect(rows
8d00: 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65  .length).to.be.e
8d10: 71 75 61 6c 28 63 6e 74 29 0a 20 20 20 20 20 20  qual(cnt).      
8d20: 20 20 2f 2f 20 74 65 73 74 20 74 68 65 20 63 6f    // test the co
8d30: 6c 73 0a 20 20 20 20 20 20 20 20 66 6f 72 20 28  ls.        for (
8d40: 72 20 3d 20 30 3b 20 72 20 3c 20 72 6f 77 73 2e  r = 0; r < rows.
8d50: 6c 65 6e 67 74 68 3b 20 72 2b 2b 29 20 7b 0a 20  length; r++) {. 
8d60: 20 20 20 20 20 20 20 20 20 63 20 3d 20 6e 61 6d           c = nam
8d70: 65 5b 31 5d 2e 74 6f 55 70 70 65 72 43 61 73 65  e[1].toUpperCase
8d80: 28 29 0a 20 20 20 20 20 20 20 20 20 20 73 20 3d  ().          s =
8d90: 20 72 20 2b 20 31 0a 20 20 20 20 20 20 20 20 20   r + 1.         
8da0: 20 63 65 6c 6c 73 20 3d 20 72 6f 77 73 5b 72 5d   cells = rows[r]
8db0: 2e 63 65 6c 6c 73 0a 20 20 20 20 20 20 20 20 20  .cells.         
8dc0: 20 74 65 6d 70 6c 20 3d 20 63 20 3d 3d 3d 20 27   templ = c === '
8dd0: 42 27 20 3f 20 27 52 27 20 2b 20 73 20 2b 20 27  B' ? 'R' + s + '
8de0: 2d 43 27 20 3a 20 63 20 2b 20 27 2d 27 0a 20 20  -C' : c + '-'.  
8df0: 20 20 20 20 20 20 20 20 65 78 70 65 63 74 28 63          expect(c
8e00: 65 6c 6c 73 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e  ells.length).to.
8e10: 62 65 2e 65 71 75 61 6c 28 32 29 0a 20 20 20 20  be.equal(2).    
8e20: 20 20 20 20 20 20 65 78 70 65 63 74 28 63 65 6c        expect(cel
8e30: 6c 73 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29  ls[0].innerHTML)
8e40: 2e 74 6f 2e 63 6f 6e 74 61 69 6e 28 74 65 6d 70  .to.contain(temp
8e50: 6c 20 2b 20 27 31 27 29 0a 20 20 20 20 20 20 20  l + '1').       
8e60: 20 20 20 65 78 70 65 63 74 28 63 65 6c 6c 73 5b     expect(cells[
8e70: 31 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29 2e 74 6f  1].innerHTML).to
8e80: 2e 63 6f 6e 74 61 69 6e 28 74 65 6d 70 6c 20 2b  .contain(templ +
8e90: 20 27 32 27 29 0a 20 20 20 20 20 20 20 20 7d 0a   '2').        }.
8ea0: 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 0a 20        }.    }.. 
8eb0: 20 20 20 2f 2f 20 74 65 73 74 20 63 61 70 74 69     // test capti
8ec0: 6f 6e 2c 20 63 6f 6c 67 72 6f 75 70 20 61 6e 64  on, colgroup and
8ed0: 20 63 6f 6c 20 65 6c 65 6d 65 6e 74 73 0a 20 20   col elements.  
8ee0: 20 20 66 75 6e 63 74 69 6f 6e 20 74 65 73 74 4f    function testO
8ef0: 74 68 65 72 28 72 6f 6f 74 2c 20 6e 61 6d 65 29  ther(root, name)
8f00: 20 7b 0a 20 20 20 20 20 20 76 61 72 20 63 6f 6c   {.      var col
8f10: 73 2c 20 73 20 3d 20 6e 61 6d 65 20 2b 20 27 2e  s, s = name + '.
8f20: 6c 65 6e 67 74 68 3a 20 27 0a 0a 20 20 20 20 20  length: '..     
8f30: 20 2f 2f 20 77 65 27 6c 6c 20 73 65 61 72 63 68   // we'll search
8f40: 20 74 68 65 20 70 61 72 65 6e 74 20 66 6f 72 20   the parent for 
8f50: 3c 63 6f 6c 3e 2c 20 6c 61 74 65 72 20 69 6e 20  <col>, later in 
8f60: 74 68 65 20 73 77 69 74 63 68 0a 20 20 20 20 20  the switch.     
8f70: 20 69 66 20 28 6e 61 6d 65 20 21 3d 3d 20 27 63   if (name !== 'c
8f80: 6f 6c 27 29 20 7b 0a 20 20 20 20 20 20 20 20 72  ol') {.        r
8f90: 6f 6f 74 20 3d 20 72 6f 6f 74 2e 67 65 74 45 6c  oot = root.getEl
8fa0: 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65 28  ementsByTagName(
8fb0: 6e 61 6d 65 29 0a 20 20 20 20 20 20 20 20 65 78  name).        ex
8fc0: 70 65 63 74 28 73 20 2b 20 72 6f 6f 74 2e 6c 65  pect(s + root.le
8fd0: 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61  ngth).to.be.equa
8fe0: 6c 28 73 20 2b 20 27 31 27 29 0a 20 20 20 20 20  l(s + '1').     
8ff0: 20 20 20 72 6f 6f 74 20 3d 20 72 6f 6f 74 5b 30     root = root[0
9000: 5d 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20  ].      }.      
9010: 73 77 69 74 63 68 20 28 6e 61 6d 65 29 20 7b 0a  switch (name) {.
9020: 20 20 20 20 20 20 63 61 73 65 20 27 63 61 70 74        case 'capt
9030: 69 6f 6e 27 3a 0a 20 20 20 20 20 20 20 20 65 78  ion':.        ex
9040: 70 65 63 74 28 72 6f 6f 74 2e 69 6e 6e 65 72 48  pect(root.innerH
9050: 54 4d 4c 29 2e 74 6f 2e 63 6f 6e 74 61 69 6e 28  TML).to.contain(
9060: 27 54 69 74 6c 65 27 29 0a 20 20 20 20 20 20 20  'Title').       
9070: 20 62 72 65 61 6b 0a 20 20 20 20 20 20 63 61 73   break.      cas
9080: 65 20 27 63 6f 6c 67 72 6f 75 70 27 3a 0a 20 20  e 'colgroup':.  
9090: 20 20 20 20 63 61 73 65 20 27 63 6f 6c 27 3a 0a      case 'col':.
90a0: 20 20 20 20 20 20 20 20 63 6f 6c 73 20 3d 20 72          cols = r
90b0: 6f 6f 74 2e 67 65 74 45 6c 65 6d 65 6e 74 73 42  oot.getElementsB
90c0: 79 54 61 67 4e 61 6d 65 28 27 63 6f 6c 27 29 0a  yTagName('col').
90d0: 20 20 20 20 20 20 20 20 65 78 70 65 63 74 28 63          expect(c
90e0: 6f 6c 73 29 2e 74 6f 2e 68 61 76 65 2e 6c 65 6e  ols).to.have.len
90f0: 67 74 68 28 32 29 0a 20 20 20 20 20 20 20 20 65  gth(2).        e
9100: 78 70 65 63 74 28 63 6f 6c 73 5b 30 5d 2e 77 69  xpect(cols[0].wi
9110: 64 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  dth).to.be.equal
9120: 28 27 31 35 30 27 29 0a 20 20 20 20 20 20 20 20  ('150').        
9130: 65 78 70 65 63 74 28 63 6f 6c 73 5b 31 5d 2e 77  expect(cols[1].w
9140: 69 64 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61  idth).to.be.equa
9150: 6c 28 27 32 30 30 27 29 0a 20 20 20 20 20 20 20  l('200').       
9160: 20 62 72 65 61 6b 0a 20 20 20 20 20 20 64 65 66   break.      def
9170: 61 75 6c 74 3a 0a 20 20 20 20 20 20 20 20 62 72  ault:.        br
9180: 65 61 6b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20  eak.      }.    
9190: 7d 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 73 65  }.  })..  it('se
91a0: 6c 65 63 74 20 61 73 20 72 6f 6f 74 20 65 6c 65  lect as root ele
91b0: 6d 65 6e 74 20 6f 66 20 63 75 73 74 6f 6d 20 72  ment of custom r
91c0: 69 6f 74 20 74 61 67 27 2c 20 66 75 6e 63 74 69  iot tag', functi
91d0: 6f 6e 20 28 29 20 7b 0a 20 20 20 20 2f 2f 20 73  on () {.    // s
91e0: 6b 69 70 20 74 68 69 73 20 74 65 73 74 20 6f 6e  kip this test on
91f0: 20 49 45 39 0a 20 20 20 20 2f 2f 20 62 65 63 61   IE9.    // beca
9200: 75 73 65 20 69 74 20 66 61 69 6c 73 20 66 6f 72  use it fails for
9210: 20 6e 6f 20 72 65 61 73 6f 6e 0a 20 20 20 20 69   no reason.    i
9220: 66 20 28 49 45 5f 56 45 52 53 49 4f 4e 20 3c 3d  f (IE_VERSION <=
9230: 20 39 29 20 72 65 74 75 72 6e 0a 0a 20 20 20 20   9) return..    
9240: 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 73 65 6c  injectHTML('<sel
9250: 65 63 74 2d 74 65 73 74 3e 3c 2f 73 65 6c 65 63  ect-test></selec
9260: 74 2d 74 65 73 74 3e 27 29 0a 0a 20 20 20 20 76  t-test>')..    v
9270: 61 72 0a 20 20 20 20 20 20 43 48 4f 4f 53 45 20  ar.      CHOOSE 
9280: 3d 20 30 2c 20 20 20 20 20 2f 2f 20 6f 70 74 69  = 0,     // opti
9290: 6f 6e 20 61 6c 6f 6e 65 0a 20 20 20 20 20 20 4f  on alone.      O
92a0: 50 54 49 4f 4e 20 3d 20 31 2c 20 20 20 20 20 2f  PTION = 1,     /
92b0: 2f 20 6c 6f 6f 70 65 64 20 6f 70 74 69 6f 6e 0a  / looped option.
92c0: 20 20 20 20 20 20 4f 50 54 47 52 50 20 3d 20 32        OPTGRP = 2
92d0: 2c 20 20 20 20 20 2f 2f 20 6f 70 74 67 72 6f 75  ,     // optgrou
92e0: 70 20 77 69 74 68 20 6f 70 74 69 6f 6e 73 0a 20  p with options. 
92f0: 20 20 20 20 20 6c 69 73 74 20 3d 20 7b 0a 20 20       list = {.  
9300: 20 20 20 20 20 20 27 73 65 6c 65 63 74 2d 73 69        'select-si
9310: 6e 67 6c 65 2d 6f 70 74 69 6f 6e 27 3a 20 5b 30  ngle-option': [0
9320: 2c 20 43 48 4f 4f 53 45 5d 2c 0a 20 20 20 20 20  , CHOOSE],.     
9330: 20 20 20 27 73 65 6c 65 63 74 2d 65 61 63 68 2d     'select-each-
9340: 6f 70 74 69 6f 6e 27 3a 20 5b 31 2c 20 4f 50 54  option': [1, OPT
9350: 49 4f 4e 5d 2c 0a 20 20 20 20 20 20 20 20 27 73  ION],.        's
9360: 65 6c 65 63 74 2d 65 61 63 68 2d 6f 70 74 69 6f  elect-each-optio
9370: 6e 2d 70 72 6f 6d 70 74 27 3a 20 5b 32 2c 20 43  n-prompt': [2, C
9380: 48 4f 4f 53 45 2c 20 4f 50 54 49 4f 4e 5d 2c 0a  HOOSE, OPTION],.
9390: 20 20 20 20 20 20 20 20 27 73 65 6c 65 63 74 2d          'select-
93a0: 65 61 63 68 2d 74 77 6f 2d 6f 70 74 69 6f 6e 73  each-two-options
93b0: 27 3a 20 5b 34 2c 20 4f 50 54 49 4f 4e 2c 20 4f  ': [4, OPTION, O
93c0: 50 54 49 4f 4e 5d 2c 0a 20 20 20 20 20 20 20 20  PTION],.        
93d0: 27 73 65 6c 65 63 74 2d 6f 70 74 67 72 6f 75 70  'select-optgroup
93e0: 2d 65 61 63 68 2d 6f 70 74 69 6f 6e 27 3a 20 5b  -each-option': [
93f0: 30 2c 20 4f 50 54 47 52 50 5d 2c 0a 20 20 20 20  0, OPTGRP],.    
9400: 20 20 20 20 27 73 65 6c 65 63 74 2d 6f 70 74 67      'select-optg
9410: 72 6f 75 70 2d 65 61 63 68 2d 6f 70 74 69 6f 6e  roup-each-option
9420: 2d 70 72 6f 6d 70 74 27 3a 20 5b 33 2c 20 4f 50  -prompt': [3, OP
9430: 54 47 52 50 2c 20 43 48 4f 4f 53 45 5d 2c 0a 20  TGRP, CHOOSE],. 
9440: 20 20 20 20 20 20 20 27 73 65 6c 65 63 74 2d 74         'select-t
9450: 77 6f 2d 6f 70 74 67 72 6f 75 70 2d 65 61 63 68  wo-optgroup-each
9460: 2d 6f 70 74 69 6f 6e 27 3a 20 5b 33 2c 20 4f 50  -option': [3, OP
9470: 54 47 52 50 2c 20 43 48 4f 4f 53 45 2c 20 4f 50  TGRP, CHOOSE, OP
9480: 54 47 52 50 5d 2c 0a 20 20 20 20 20 20 20 20 27  TGRP],.        '
9490: 73 65 6c 65 63 74 2d 65 61 63 68 2d 6f 70 74 67  select-each-optg
94a0: 72 6f 75 70 27 3a 20 5b 30 2c 20 4f 50 54 47 52  roup': [0, OPTGR
94b0: 50 2c 20 4f 50 54 47 52 50 5d 0a 20 20 20 20 20  P, OPTGRP].     
94c0: 20 7d 2c 0a 20 20 20 20 20 20 73 65 6c 2c 20 64   },.      sel, d
94d0: 61 74 2c 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d  at, tag = riot.m
94e0: 6f 75 6e 74 28 27 73 65 6c 65 63 74 2d 74 65 73  ount('select-tes
94f0: 74 27 29 5b 30 5d 0a 0a 20 20 20 20 65 78 70 65  t')[0]..    expe
9500: 63 74 28 74 61 67 29 2e 74 6f 2e 6e 6f 74 2e 62  ct(tag).to.not.b
9510: 65 2e 65 6d 70 74 79 0a 0a 20 20 20 20 66 6f 72  e.empty..    for
9520: 20 28 63 6f 6e 73 74 20 6e 61 6d 65 20 69 6e 20   (const name in 
9530: 6c 69 73 74 29 20 7b 0a 20 20 20 20 20 20 64 61  list) {.      da
9540: 74 20 3d 20 6c 69 73 74 5b 6e 61 6d 65 5d 0a 20  t = list[name]. 
9550: 20 20 20 20 20 73 65 6c 20 3d 20 24 28 27 73 65       sel = $('se
9560: 6c 65 63 74 5b 64 61 74 61 2d 69 73 3d 27 20 2b  lect[data-is=' +
9570: 20 6e 61 6d 65 20 2b 20 27 5d 27 2c 20 74 61 67   name + ']', tag
9580: 2e 72 6f 6f 74 29 0a 20 20 20 20 20 20 65 78 70  .root).      exp
9590: 65 63 74 28 73 65 6c 29 2e 74 6f 2e 6e 6f 74 2e  ect(sel).to.not.
95a0: 62 65 2e 65 6d 70 74 79 0a 20 20 20 20 20 20 65  be.empty.      e
95b0: 78 70 65 63 74 28 73 65 6c 2e 73 65 6c 65 63 74  xpect(sel.select
95c0: 65 64 49 6e 64 65 78 29 2e 74 6f 2e 62 65 2e 65  edIndex).to.be.e
95d0: 71 75 61 6c 28 64 61 74 5b 30 5d 2c 20 6e 61 6d  qual(dat[0], nam
95e0: 65 20 2b 20 27 2e 73 65 6c 65 63 74 49 6e 64 65  e + '.selectInde
95f0: 78 20 27 20 2b 20 73 65 6c 2e 73 65 6c 65 63 74  x ' + sel.select
9600: 65 64 49 6e 64 65 78 20 2b 20 27 20 65 78 70 65  edIndex + ' expe
9610: 63 74 65 64 20 74 6f 20 62 65 20 27 20 2b 20 64  cted to be ' + d
9620: 61 74 5b 30 5d 29 0a 20 20 20 20 20 20 76 61 72  at[0]).      var
9630: 20 73 31 20 3d 20 6c 69 73 74 46 72 6f 6d 53 65   s1 = listFromSe
9640: 6c 28 73 65 6c 29 0a 20 20 20 20 20 20 76 61 72  l(sel).      var
9650: 20 73 32 20 3d 20 6c 69 73 74 46 72 6f 6d 44 61   s2 = listFromDa
9660: 74 28 64 61 74 29 0a 20 20 20 20 20 20 65 78 70  t(dat).      exp
9670: 65 63 74 28 73 31 29 2e 74 6f 2e 62 65 2e 65 71  ect(s1).to.be.eq
9680: 75 61 6c 28 73 32 29 0a 20 20 20 20 7d 0a 0a 20  ual(s2).    }.. 
9690: 20 20 20 66 75 6e 63 74 69 6f 6e 20 6c 69 73 74     function list
96a0: 46 72 6f 6d 44 61 74 28 64 61 74 29 20 7b 0a 20  FromDat(dat) {. 
96b0: 20 20 20 20 20 76 61 72 20 6f 70 20 3d 20 5b 5d       var op = []
96c0: 2c 20 73 20 3d 20 27 4f 70 74 31 2c 4f 70 74 32  , s = 'Opt1,Opt2
96d0: 2c 4f 70 74 33 27 0a 0a 20 20 20 20 20 20 66 6f  ,Opt3'..      fo
96e0: 72 20 28 76 61 72 20 69 20 3d 20 31 3b 20 69 20  r (var i = 1; i 
96f0: 3c 20 64 61 74 2e 6c 65 6e 67 74 68 3b 20 69 2b  < dat.length; i+
9700: 2b 29 20 7b 0a 20 20 20 20 20 20 20 20 69 66 20  +) {.        if 
9710: 28 64 61 74 5b 69 5d 20 3d 3d 3d 20 4f 50 54 47  (dat[i] === OPTG
9720: 52 50 29 20 6f 70 2e 70 75 73 68 28 27 47 2c 27  RP) op.push('G,'
9730: 20 2b 20 73 29 0a 20 20 20 20 20 20 20 20 65 6c   + s).        el
9740: 73 65 20 69 66 20 28 64 61 74 5b 69 5d 20 3d 3d  se if (dat[i] ==
9750: 3d 20 4f 50 54 49 4f 4e 29 20 6f 70 2e 70 75 73  = OPTION) op.pus
9760: 68 28 73 29 0a 20 20 20 20 20 20 20 20 65 6c 73  h(s).        els
9770: 65 20 6f 70 2e 70 75 73 68 28 27 28 63 68 6f 6f  e op.push('(choo
9780: 73 65 29 27 29 0a 20 20 20 20 20 20 7d 0a 0a 20  se)').      }.. 
9790: 20 20 20 20 20 72 65 74 75 72 6e 20 6f 70 2e 6a       return op.j
97a0: 6f 69 6e 28 27 2c 27 29 0a 20 20 20 20 7d 0a 0a  oin(',').    }..
97b0: 20 20 20 20 66 75 6e 63 74 69 6f 6e 20 6c 69 73      function lis
97c0: 74 46 72 6f 6d 53 65 6c 28 65 6c 29 20 7b 0a 20  tFromSel(el) {. 
97d0: 20 20 20 20 20 76 61 72 20 6f 70 20 3d 20 5b 5d       var op = []
97e0: 0a 20 20 20 20 20 20 65 6c 20 3d 20 65 6c 2e 66  .      el = el.f
97f0: 69 72 73 74 43 68 69 6c 64 0a 0a 20 20 20 20 20  irstChild..     
9800: 20 77 68 69 6c 65 20 28 65 6c 29 20 7b 0a 20 20   while (el) {.  
9810: 20 20 20 20 20 20 69 66 20 28 65 6c 2e 74 61 67        if (el.tag
9820: 4e 61 6d 65 20 3d 3d 3d 20 27 4f 50 54 47 52 4f  Name === 'OPTGRO
9830: 55 50 27 29 20 7b 0a 20 20 20 20 20 20 20 20 20  UP') {.         
9840: 20 6f 70 2e 70 75 73 68 28 27 47 27 29 0a 20 20   op.push('G').  
9850: 20 20 20 20 20 20 20 20 6f 70 20 3d 20 6f 70 2e          op = op.
9860: 63 6f 6e 63 61 74 28 6c 69 73 74 46 72 6f 6d 53  concat(listFromS
9870: 65 6c 28 65 6c 29 29 0a 20 20 20 20 20 20 20 20  el(el)).        
9880: 7d 20 65 6c 73 65 20 69 66 20 28 65 6c 2e 74 61  } else if (el.ta
9890: 67 4e 61 6d 65 20 3d 3d 3d 20 27 4f 50 54 49 4f  gName === 'OPTIO
98a0: 4e 27 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20  N') {.          
98b0: 6f 70 2e 70 75 73 68 28 65 6c 2e 74 65 78 74 29  op.push(el.text)
98c0: 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20  .        }.     
98d0: 20 20 20 65 6c 20 3d 20 65 6c 2e 6e 65 78 74 53     el = el.nextS
98e0: 69 62 6c 69 6e 67 0a 20 20 20 20 20 20 7d 0a 0a  ibling.      }..
98f0: 20 20 20 20 20 20 72 65 74 75 72 6e 20 6f 70 2e        return op.
9900: 6a 6f 69 6e 28 27 2c 27 29 0a 20 20 20 20 7d 0a  join(',').    }.
9910: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
9920: 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 6c  ().  })..  it('l
9930: 6f 6f 70 73 20 67 65 74 20 72 65 6e 64 65 72 65  oops get rendere
9940: 64 20 63 6f 72 72 65 63 74 6c 79 20 61 6c 73 6f  d correctly also
9950: 20 77 68 65 6e 20 72 69 6f 74 2e 62 72 61 63 6b   when riot.brack
9960: 65 74 73 20 67 65 74 20 63 68 61 6e 67 65 64 27  ets get changed'
9970: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 0a  , function() {..
9980: 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27      injectHTML('
9990: 3c 6c 6f 6f 70 2d 64 6f 75 62 6c 65 2d 63 75 72  <loop-double-cur
99a0: 6c 79 2d 62 72 61 63 6b 65 74 73 3e 3c 2f 6c 6f  ly-brackets></lo
99b0: 6f 70 2d 64 6f 75 62 6c 65 2d 63 75 72 6c 79 2d  op-double-curly-
99c0: 62 72 61 63 6b 65 74 73 3e 27 29 0a 0a 20 20 20  brackets>')..   
99d0: 20 2f 2f 20 63 68 61 6e 67 65 20 74 68 65 20 62   // change the b
99e0: 72 61 63 6b 65 74 73 0a 20 20 20 20 72 69 6f 74  rackets.    riot
99f0: 2e 73 65 74 74 69 6e 67 73 2e 62 72 61 63 6b 65  .settings.bracke
9a00: 74 73 20 3d 20 27 7b 7b 20 7d 7d 27 0a 20 20 20  ts = '{{ }}'.   
9a10: 20 63 6f 6e 73 74 20 74 61 67 20 3d 20 72 69 6f   const tag = rio
9a20: 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f 70 2d 64 6f  t.mount('loop-do
9a30: 75 62 6c 65 2d 63 75 72 6c 79 2d 62 72 61 63 6b  uble-curly-brack
9a40: 65 74 73 27 29 5b 30 5d 2c 0a 20 20 20 20 20 20  ets')[0],.      
9a50: 70 73 20 3d 20 24 24 28 27 70 27 2c 20 74 61 67  ps = $$('p', tag
9a60: 2e 72 6f 6f 74 29 0a 0a 20 20 20 20 65 78 70 65  .root)..    expe
9a70: 63 74 28 70 73 2e 6c 65 6e 67 74 68 29 2e 74 6f  ct(ps.length).to
9a80: 2e 62 65 2e 65 71 75 61 6c 28 32 29 0a 20 20 20  .be.equal(2).   
9a90: 20 65 78 70 65 63 74 28 70 73 5b 30 5d 2e 69 6e   expect(ps[0].in
9aa0: 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65  nerHTML).to.be.e
9ab0: 71 75 61 6c 28 70 73 5b 31 5d 2e 69 6e 6e 65 72  qual(ps[1].inner
9ac0: 48 54 4d 4c 29 0a 20 20 20 20 65 78 70 65 63 74  HTML).    expect
9ad0: 28 70 73 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d 4c  (ps[0].innerHTML
9ae0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 68  ).to.be.equal('h
9af0: 65 6c 6c 6f 27 29 0a 20 20 20 20 74 61 67 2e 63  ello').    tag.c
9b00: 68 61 6e 67 65 28 29 0a 20 20 20 20 65 78 70 65  hange().    expe
9b10: 63 74 28 70 73 2e 6c 65 6e 67 74 68 29 2e 74 6f  ct(ps.length).to
9b20: 2e 62 65 2e 65 71 75 61 6c 28 32 29 0a 20 20 20  .be.equal(2).   
9b30: 20 65 78 70 65 63 74 28 70 73 5b 30 5d 2e 69 6e   expect(ps[0].in
9b40: 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65  nerHTML).to.be.e
9b50: 71 75 61 6c 28 70 73 5b 31 5d 2e 69 6e 6e 65 72  qual(ps[1].inner
9b60: 48 54 4d 4c 29 0a 20 20 20 20 65 78 70 65 63 74  HTML).    expect
9b70: 28 70 73 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d 4c  (ps[0].innerHTML
9b80: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 68  ).to.be.equal('h
9b90: 65 6c 6c 6f 20 77 6f 72 6c 64 27 29 0a 0a 20 20  ello world')..  
9ba0: 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a    tag.unmount().
9bb0: 20 20 20 20 72 69 6f 74 2e 73 65 74 74 69 6e 67      riot.setting
9bc0: 73 2e 62 72 61 63 6b 65 74 73 20 3d 20 27 7b 20  s.brackets = '{ 
9bd0: 7d 27 0a 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27  }'..  })..  it('
9be0: 6c 6f 6f 70 73 20 63 6f 72 72 65 63 74 6c 79 20  loops correctly 
9bf0: 6f 6e 20 61 72 72 61 79 20 73 75 62 63 6c 61 73  on array subclas
9c00: 73 65 73 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29  ses', function()
9c10: 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d   {.    injectHTM
9c20: 4c 28 27 3c 6c 6f 6f 70 2d 61 72 72 61 79 6c 69  L('<loop-arrayli
9c30: 6b 65 3e 3c 2f 6c 6f 6f 70 2d 61 72 72 61 79 6c  ke></loop-arrayl
9c40: 69 6b 65 3e 27 29 0a 20 20 20 20 63 6f 6e 73 74  ike>').    const
9c50: 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e   tag = riot.moun
9c60: 74 28 27 6c 6f 6f 70 2d 61 72 72 61 79 6c 69 6b  t('loop-arraylik
9c70: 65 27 29 5b 30 5d 2c 0a 20 20 20 20 20 20 72 6f  e')[0],.      ro
9c80: 6f 74 20 3d 20 74 61 67 2e 72 6f 6f 74 0a 20 20  ot = tag.root.  
9c90: 20 20 65 78 70 65 63 74 28 6e 6f 72 6d 61 6c 69    expect(normali
9ca0: 7a 65 48 54 4d 4c 28 72 6f 6f 74 2e 67 65 74 45  zeHTML(root.getE
9cb0: 6c 65 6d 65 6e 74 73 42 79 54 61 67 4e 61 6d 65  lementsByTagName
9cc0: 28 27 64 69 76 27 29 5b 30 5d 2e 69 6e 6e 65 72  ('div')[0].inner
9cd0: 48 54 4d 4c 29 29 0a 20 20 20 20 20 20 2e 74 6f  HTML)).      .to
9ce0: 2e 62 65 2e 65 71 75 61 6c 28 27 3c 70 3e 30 20  .be.equal('<p>0 
9cf0: 3d 20 7a 65 72 6f 3c 2f 70 3e 3c 70 3e 31 20 3d  = zero</p><p>1 =
9d00: 20 6f 6e 65 3c 2f 70 3e 3c 70 3e 32 20 3d 20 74   one</p><p>2 = t
9d10: 77 6f 3c 2f 70 3e 3c 70 3e 33 20 3d 20 74 68 72  wo</p><p>3 = thr
9d20: 65 65 3c 2f 70 3e 27 29 0a 20 20 20 20 74 61 67  ee</p>').    tag
9d30: 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a  .unmount().  }).
9d40: 0a 0a 20 20 69 74 28 27 76 69 72 74 75 61 6c 20  ..  it('virtual 
9d50: 74 61 67 73 20 6d 6f 75 6e 74 20 69 6e 6e 65 72  tags mount inner
9d60: 20 63 6f 6e 74 65 6e 74 20 61 6e 64 20 6e 6f 74   content and not
9d70: 20 74 68 65 20 76 69 72 74 75 61 6c 20 74 61 67   the virtual tag
9d80: 20 72 6f 6f 74 27 2c 20 66 75 6e 63 74 69 6f 6e   root', function
9d90: 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48  () {.    injectH
9da0: 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 76 69 72 74 75  TML('<loop-virtu
9db0: 61 6c 3e 3c 2f 6c 6f 6f 70 2d 76 69 72 74 75 61  al></loop-virtua
9dc0: 6c 3e 27 29 20 2f 2f 20 6e 6f 2d 72 65 6f 72 64  l>') // no-reord
9dd0: 65 72 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67  er.    const tag
9de0: 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c   = riot.mount('l
9df0: 6f 6f 70 2d 76 69 72 74 75 61 6c 27 29 5b 30 5d  oop-virtual')[0]
9e00: 2c 0a 20 20 20 20 20 20 65 6c 73 20 3d 20 74 61  ,.      els = ta
9e10: 67 2e 72 6f 6f 74 2e 63 68 69 6c 64 72 65 6e 0a  g.root.children.
9e20: 0a 20 20 20 20 65 6c 73 5b 30 5d 2e 73 65 74 41  .    els[0].setA
9e30: 74 74 72 69 62 75 74 65 28 27 74 65 73 74 27 2c  ttribute('test',
9e40: 20 27 6f 6b 27 29 0a 20 20 20 20 65 78 70 65 63   'ok').    expec
9e50: 74 28 65 6c 73 5b 30 5d 2e 74 61 67 4e 61 6d 65  t(els[0].tagName
9e60: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 44  ).to.be.equal('D
9e70: 54 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 65  T').    expect(e
9e80: 6c 73 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29  ls[0].innerHTML)
9e90: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 43 6f  .to.be.equal('Co
9ea0: 66 66 65 65 27 29 0a 20 20 20 20 65 78 70 65 63  ffee').    expec
9eb0: 74 28 65 6c 73 5b 31 5d 2e 74 61 67 4e 61 6d 65  t(els[1].tagName
9ec0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 44  ).to.be.equal('D
9ed0: 44 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 65  D').    expect(e
9ee0: 6c 73 5b 31 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29  ls[1].innerHTML)
9ef0: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 42 6c  .to.be.equal('Bl
9f00: 61 63 6b 20 68 6f 74 20 64 72 69 6e 6b 27 29 0a  ack hot drink').
9f10: 20 20 20 20 65 78 70 65 63 74 28 65 6c 73 5b 32      expect(els[2
9f20: 5d 2e 74 61 67 4e 61 6d 65 29 2e 74 6f 2e 62 65  ].tagName).to.be
9f30: 2e 65 71 75 61 6c 28 27 44 54 27 29 0a 20 20 20  .equal('DT').   
9f40: 20 65 78 70 65 63 74 28 65 6c 73 5b 32 5d 2e 69   expect(els[2].i
9f50: 6e 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e  nnerHTML).to.be.
9f60: 65 71 75 61 6c 28 27 4d 69 6c 6b 27 29 0a 20 20  equal('Milk').  
9f70: 20 20 65 78 70 65 63 74 28 65 6c 73 5b 33 5d 2e    expect(els[3].
9f80: 74 61 67 4e 61 6d 65 29 2e 74 6f 2e 62 65 2e 65  tagName).to.be.e
9f90: 71 75 61 6c 28 27 44 44 27 29 0a 20 20 20 20 65  qual('DD').    e
9fa0: 78 70 65 63 74 28 65 6c 73 5b 33 5d 2e 69 6e 6e  xpect(els[3].inn
9fb0: 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65 71  erHTML).to.be.eq
9fc0: 75 61 6c 28 27 57 68 69 74 65 20 63 6f 6c 64 20  ual('White cold 
9fd0: 64 72 69 6e 6b 27 29 0a 0a 20 20 20 20 74 61 67  drink')..    tag
9fe0: 2e 64 61 74 61 2e 72 65 76 65 72 73 65 28 29 0a  .data.reverse().
9ff0: 20 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 29      tag.update()
a000: 0a 0a 20 20 20 20 65 78 70 65 63 74 28 65 6c 73  ..    expect(els
a010: 5b 30 5d 2e 67 65 74 41 74 74 72 69 62 75 74 65  [0].getAttribute
a020: 28 27 74 65 73 74 27 29 29 2e 74 6f 2e 62 65 2e  ('test')).to.be.
a030: 65 71 75 61 6c 28 27 6f 6b 27 29 20 2f 2f 20 73  equal('ok') // s
a040: 61 6d 65 20 70 6c 61 63 65 20 61 66 74 65 72 20  ame place after 
a050: 72 65 76 65 72 73 65 0a 20 20 20 20 65 78 70 65  reverse.    expe
a060: 63 74 28 65 6c 73 5b 32 5d 2e 74 61 67 4e 61 6d  ct(els[2].tagNam
a070: 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  e).to.be.equal('
a080: 44 54 27 29 0a 20 20 20 20 65 78 70 65 63 74 28  DT').    expect(
a090: 65 6c 73 5b 32 5d 2e 69 6e 6e 65 72 48 54 4d 4c  els[2].innerHTML
a0a0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 43  ).to.be.equal('C
a0b0: 6f 66 66 65 65 27 29 0a 20 20 20 20 65 78 70 65  offee').    expe
a0c0: 63 74 28 65 6c 73 5b 33 5d 2e 74 61 67 4e 61 6d  ct(els[3].tagNam
a0d0: 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  e).to.be.equal('
a0e0: 44 44 27 29 0a 20 20 20 20 65 78 70 65 63 74 28  DD').    expect(
a0f0: 65 6c 73 5b 33 5d 2e 69 6e 6e 65 72 48 54 4d 4c  els[3].innerHTML
a100: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 42  ).to.be.equal('B
a110: 6c 61 63 6b 20 68 6f 74 20 64 72 69 6e 6b 27 29  lack hot drink')
a120: 0a 20 20 20 20 65 78 70 65 63 74 28 65 6c 73 5b  .    expect(els[
a130: 30 5d 2e 74 61 67 4e 61 6d 65 29 2e 74 6f 2e 62  0].tagName).to.b
a140: 65 2e 65 71 75 61 6c 28 27 44 54 27 29 0a 20 20  e.equal('DT').  
a150: 20 20 65 78 70 65 63 74 28 65 6c 73 5b 30 5d 2e    expect(els[0].
a160: 69 6e 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65  innerHTML).to.be
a170: 2e 65 71 75 61 6c 28 27 4d 69 6c 6b 27 29 0a 20  .equal('Milk'). 
a180: 20 20 20 65 78 70 65 63 74 28 65 6c 73 5b 31 5d     expect(els[1]
a190: 2e 74 61 67 4e 61 6d 65 29 2e 74 6f 2e 62 65 2e  .tagName).to.be.
a1a0: 65 71 75 61 6c 28 27 44 44 27 29 0a 20 20 20 20  equal('DD').    
a1b0: 65 78 70 65 63 74 28 65 6c 73 5b 31 5d 2e 69 6e  expect(els[1].in
a1c0: 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65  nerHTML).to.be.e
a1d0: 71 75 61 6c 28 27 57 68 69 74 65 20 63 6f 6c 64  qual('White cold
a1e0: 20 64 72 69 6e 6b 27 29 0a 0a 20 20 20 20 74 61   drink')..    ta
a1f0: 67 2e 64 61 74 61 2e 75 6e 73 68 69 66 74 28 7b  g.data.unshift({
a200: 20 6b 65 79 3a 20 27 54 65 61 27 2c 20 76 61 6c   key: 'Tea', val
a210: 75 65 3a 20 27 48 6f 74 20 6f 72 20 63 6f 6c 64  ue: 'Hot or cold
a220: 20 64 72 69 6e 6b 27 20 7d 29 0a 20 20 20 20 74   drink' }).    t
a230: 61 67 2e 75 70 64 61 74 65 28 29 0a 20 20 20 20  ag.update().    
a240: 65 78 70 65 63 74 28 65 6c 73 5b 30 5d 2e 74 61  expect(els[0].ta
a250: 67 4e 61 6d 65 29 2e 74 6f 2e 62 65 2e 65 71 75  gName).to.be.equ
a260: 61 6c 28 27 44 54 27 29 0a 20 20 20 20 65 78 70  al('DT').    exp
a270: 65 63 74 28 65 6c 73 5b 30 5d 2e 69 6e 6e 65 72  ect(els[0].inner
a280: 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65 71 75 61  HTML).to.be.equa
a290: 6c 28 27 54 65 61 27 29 0a 20 20 20 20 65 78 70  l('Tea').    exp
a2a0: 65 63 74 28 65 6c 73 5b 31 5d 2e 74 61 67 4e 61  ect(els[1].tagNa
a2b0: 6d 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  me).to.be.equal(
a2c0: 27 44 44 27 29 0a 20 20 20 20 65 78 70 65 63 74  'DD').    expect
a2d0: 28 65 6c 73 5b 31 5d 2e 69 6e 6e 65 72 48 54 4d  (els[1].innerHTM
a2e0: 4c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  L).to.be.equal('
a2f0: 48 6f 74 20 6f 72 20 63 6f 6c 64 20 64 72 69 6e  Hot or cold drin
a300: 6b 27 29 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f  k').    tag.unmo
a310: 75 6e 74 28 29 0a 0a 20 20 20 20 69 6e 6a 65 63  unt()..    injec
a320: 74 48 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 76 69 72  tHTML('<loop-vir
a330: 74 75 61 6c 2d 72 65 6f 72 64 65 72 3e 3c 2f 6c  tual-reorder></l
a340: 6f 6f 70 2d 76 69 72 74 75 61 6c 2d 72 65 6f 72  oop-virtual-reor
a350: 64 65 72 3e 27 29 0a 0a 20 20 20 20 63 6f 6e 73  der>')..    cons
a360: 74 20 74 61 67 32 20 3d 20 72 69 6f 74 2e 6d 6f  t tag2 = riot.mo
a370: 75 6e 74 28 27 6c 6f 6f 70 2d 76 69 72 74 75 61  unt('loop-virtua
a380: 6c 2d 72 65 6f 72 64 65 72 27 29 5b 30 5d 2c 0a  l-reorder')[0],.
a390: 20 20 20 20 20 20 65 6c 73 32 20 3d 20 74 61 67        els2 = tag
a3a0: 32 2e 72 6f 6f 74 2e 63 68 69 6c 64 72 65 6e 0a  2.root.children.
a3b0: 0a 20 20 20 20 65 6c 73 32 5b 30 5d 2e 73 65 74  .    els2[0].set
a3c0: 41 74 74 72 69 62 75 74 65 28 27 74 65 73 74 27  Attribute('test'
a3d0: 2c 20 27 6f 6b 27 29 0a 20 20 20 20 65 78 70 65  , 'ok').    expe
a3e0: 63 74 28 65 6c 73 32 5b 30 5d 2e 67 65 74 41 74  ct(els2[0].getAt
a3f0: 74 72 69 62 75 74 65 28 27 74 65 73 74 27 29 29  tribute('test'))
a400: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 6f 6b  .to.be.equal('ok
a410: 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 65 6c  ').    expect(el
a420: 73 32 5b 30 5d 2e 74 61 67 4e 61 6d 65 29 2e 74  s2[0].tagName).t
a430: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 44 54 27 29  o.be.equal('DT')
a440: 0a 20 20 20 20 65 78 70 65 63 74 28 65 6c 73 32  .    expect(els2
a450: 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29 2e 74  [0].innerHTML).t
a460: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 43 6f 66 66  o.be.equal('Coff
a470: 65 65 27 29 0a 20 20 20 20 65 78 70 65 63 74 28  ee').    expect(
a480: 65 6c 73 32 5b 31 5d 2e 74 61 67 4e 61 6d 65 29  els2[1].tagName)
a490: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 44 44  .to.be.equal('DD
a4a0: 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 65 6c  ').    expect(el
a4b0: 73 32 5b 31 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29  s2[1].innerHTML)
a4c0: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 42 6c  .to.be.equal('Bl
a4d0: 61 63 6b 20 68 6f 74 20 64 72 69 6e 6b 27 29 0a  ack hot drink').
a4e0: 20 20 20 20 65 78 70 65 63 74 28 65 6c 73 32 5b      expect(els2[
a4f0: 32 5d 2e 74 61 67 4e 61 6d 65 29 2e 74 6f 2e 62  2].tagName).to.b
a500: 65 2e 65 71 75 61 6c 28 27 44 54 27 29 0a 20 20  e.equal('DT').  
a510: 20 20 65 78 70 65 63 74 28 65 6c 73 32 5b 32 5d    expect(els2[2]
a520: 2e 69 6e 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62  .innerHTML).to.b
a530: 65 2e 65 71 75 61 6c 28 27 4d 69 6c 6b 27 29 0a  e.equal('Milk').
a540: 20 20 20 20 65 78 70 65 63 74 28 65 6c 73 32 5b      expect(els2[
a550: 33 5d 2e 74 61 67 4e 61 6d 65 29 2e 74 6f 2e 62  3].tagName).to.b
a560: 65 2e 65 71 75 61 6c 28 27 44 44 27 29 0a 20 20  e.equal('DD').  
a570: 20 20 65 78 70 65 63 74 28 65 6c 73 32 5b 33 5d    expect(els2[3]
a580: 2e 69 6e 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62  .innerHTML).to.b
a590: 65 2e 65 71 75 61 6c 28 27 57 68 69 74 65 20 63  e.equal('White c
a5a0: 6f 6c 64 20 64 72 69 6e 6b 27 29 0a 0a 20 20 20  old drink')..   
a5b0: 20 74 61 67 32 2e 64 61 74 61 2e 72 65 76 65 72   tag2.data.rever
a5c0: 73 65 28 29 0a 20 20 20 20 74 61 67 32 2e 75 70  se().    tag2.up
a5d0: 64 61 74 65 28 29 0a 0a 20 20 20 20 65 78 70 65  date()..    expe
a5e0: 63 74 28 65 6c 73 32 5b 32 5d 2e 67 65 74 41 74  ct(els2[2].getAt
a5f0: 74 72 69 62 75 74 65 28 27 74 65 73 74 27 29 29  tribute('test'))
a600: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 6f 6b  .to.be.equal('ok
a610: 27 29 20 2f 2f 20 6d 6f 76 65 64 20 61 66 74 65  ') // moved afte
a620: 72 20 72 65 76 65 72 73 65 0a 20 20 20 20 65 78  r reverse.    ex
a630: 70 65 63 74 28 65 6c 73 32 5b 32 5d 2e 74 61 67  pect(els2[2].tag
a640: 4e 61 6d 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61  Name).to.be.equa
a650: 6c 28 27 44 54 27 29 0a 20 20 20 20 65 78 70 65  l('DT').    expe
a660: 63 74 28 65 6c 73 32 5b 32 5d 2e 69 6e 6e 65 72  ct(els2[2].inner
a670: 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65 71 75 61  HTML).to.be.equa
a680: 6c 28 27 43 6f 66 66 65 65 27 29 0a 20 20 20 20  l('Coffee').    
a690: 65 78 70 65 63 74 28 65 6c 73 32 5b 33 5d 2e 74  expect(els2[3].t
a6a0: 61 67 4e 61 6d 65 29 2e 74 6f 2e 62 65 2e 65 71  agName).to.be.eq
a6b0: 75 61 6c 28 27 44 44 27 29 0a 20 20 20 20 65 78  ual('DD').    ex
a6c0: 70 65 63 74 28 65 6c 73 32 5b 33 5d 2e 69 6e 6e  pect(els2[3].inn
a6d0: 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65 71  erHTML).to.be.eq
a6e0: 75 61 6c 28 27 42 6c 61 63 6b 20 68 6f 74 20 64  ual('Black hot d
a6f0: 72 69 6e 6b 27 29 0a 20 20 20 20 65 78 70 65 63  rink').    expec
a700: 74 28 65 6c 73 32 5b 30 5d 2e 74 61 67 4e 61 6d  t(els2[0].tagNam
a710: 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  e).to.be.equal('
a720: 44 54 27 29 0a 20 20 20 20 65 78 70 65 63 74 28  DT').    expect(
a730: 65 6c 73 32 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d  els2[0].innerHTM
a740: 4c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  L).to.be.equal('
a750: 4d 69 6c 6b 27 29 0a 20 20 20 20 65 78 70 65 63  Milk').    expec
a760: 74 28 65 6c 73 32 5b 31 5d 2e 74 61 67 4e 61 6d  t(els2[1].tagNam
a770: 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  e).to.be.equal('
a780: 44 44 27 29 0a 20 20 20 20 65 78 70 65 63 74 28  DD').    expect(
a790: 65 6c 73 32 5b 31 5d 2e 69 6e 6e 65 72 48 54 4d  els2[1].innerHTM
a7a0: 4c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  L).to.be.equal('
a7b0: 57 68 69 74 65 20 63 6f 6c 64 20 64 72 69 6e 6b  White cold drink
a7c0: 27 29 0a 20 20 20 20 74 61 67 32 2e 75 6e 6d 6f  ').    tag2.unmo
a7d0: 75 6e 74 28 29 0a 0a 20 20 7d 29 0a 0a 20 20 69  unt()..  })..  i
a7e0: 74 28 27 72 65 64 72 61 77 73 20 63 6f 72 72 65  t('redraws corre
a7f0: 63 74 6c 79 20 61 66 74 65 72 20 69 74 65 6d 73  ctly after items
a800: 20 74 79 70 65 20 69 73 20 73 77 61 70 70 65 64   type is swapped
a810: 20 66 72 6f 6d 20 61 72 72 61 79 20 74 6f 20 6f   from array to o
a820: 62 6a 65 63 74 20 61 6e 64 20 62 61 63 6b 27 2c  bject and back',
a830: 20 66 75 6e 63 74 69 6f 6e 20 28 29 20 7b 0a 20   function () {. 
a840: 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c     injectHTML('<
a850: 6c 6f 6f 70 2d 73 77 61 70 2d 74 79 70 65 3e 3c  loop-swap-type><
a860: 2f 6c 6f 6f 70 2d 73 77 61 70 2d 74 79 70 65 3e  /loop-swap-type>
a870: 27 29 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67  ').    const tag
a880: 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c   = riot.mount('l
a890: 6f 6f 70 2d 73 77 61 70 2d 74 79 70 65 27 29 5b  oop-swap-type')[
a8a0: 30 5d 0a 0a 20 20 20 20 74 61 67 2e 73 77 61 70  0]..    tag.swap
a8b0: 28 29 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74  ().    tag.updat
a8c0: 65 28 29 0a 20 20 20 20 76 61 72 20 65 6c 73 20  e().    var els 
a8d0: 3d 20 74 61 67 2e 72 6f 6f 74 2e 63 68 69 6c 64  = tag.root.child
a8e0: 72 65 6e 0a 20 20 20 20 65 78 70 65 63 74 28 65  ren.    expect(e
a8f0: 6c 73 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29  ls[0].innerHTML)
a900: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 33 27  .to.be.equal('3'
a910: 29 0a 20 20 20 20 65 78 70 65 63 74 28 65 6c 73  ).    expect(els
a920: 5b 31 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29 2e 74  [1].innerHTML).t
a930: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 34 27 29 0a  o.be.equal('4').
a940: 0a 20 20 20 20 74 61 67 2e 73 77 61 70 28 29 0a  .    tag.swap().
a950: 20 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 29      tag.update()
a960: 0a 20 20 20 20 65 6c 73 20 3d 20 74 61 67 2e 72  .    els = tag.r
a970: 6f 6f 74 2e 63 68 69 6c 64 72 65 6e 0a 20 20 20  oot.children.   
a980: 20 65 78 70 65 63 74 28 65 6c 73 5b 30 5d 2e 69   expect(els[0].i
a990: 6e 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e  nnerHTML).to.be.
a9a0: 65 71 75 61 6c 28 27 31 27 29 0a 20 20 20 20 65  equal('1').    e
a9b0: 78 70 65 63 74 28 65 6c 73 5b 31 5d 2e 69 6e 6e  xpect(els[1].inn
a9c0: 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65 71  erHTML).to.be.eq
a9d0: 75 61 6c 28 27 32 27 29 0a 20 20 20 20 74 61 67  ual('2').    tag
a9e0: 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a  .unmount().  }).
a9f0: 0a 20 20 69 74 28 27 73 74 69 6c 6c 20 6c 6f 6f  .  it('still loo
aa00: 70 73 20 77 69 74 68 20 72 65 73 65 72 76 65 64  ps with reserved
aa10: 20 70 72 6f 70 65 72 74 79 20 6e 61 6d 65 73 20   property names 
aa20: 23 31 35 32 36 27 2c 20 66 75 6e 63 74 69 6f 6e  #1526', function
aa30: 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48  () {.    injectH
aa40: 54 4d 4c 28 27 3c 72 65 73 65 72 76 65 64 2d 6e  TML('<reserved-n
aa50: 61 6d 65 73 3e 3c 2f 72 65 73 65 72 76 65 64 2d  ames></reserved-
aa60: 6e 61 6d 65 73 3e 27 29 0a 20 20 20 20 63 6f 6e  names>').    con
aa70: 73 74 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f  st tag = riot.mo
aa80: 75 6e 74 28 27 72 65 73 65 72 76 65 64 2d 6e 61  unt('reserved-na
aa90: 6d 65 73 27 29 5b 30 5d 0a 20 20 20 20 74 61 67  mes')[0].    tag
aaa0: 2e 72 65 6f 72 64 65 72 28 29 0a 20 20 20 20 74  .reorder().    t
aab0: 61 67 2e 75 70 64 61 74 65 28 29 0a 20 20 20 20  ag.update().    
aac0: 74 61 67 2e 72 65 6f 72 64 65 72 28 29 0a 20 20  tag.reorder().  
aad0: 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a 20    tag.update(). 
aae0: 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29     tag.unmount()
aaf0: 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 72 65 66  .  })..  it('ref
ab00: 65 72 65 6e 63 65 64 20 65 6c 65 6d 65 6e 74 73  erenced elements
ab10: 20 69 6e 20 6f 62 6a 65 63 74 20 6b 65 79 20 6c   in object key l
ab20: 6f 6f 70 20 64 6f 20 6e 6f 74 20 64 75 70 6c 69  oop do not dupli
ab30: 63 61 74 65 27 2c 20 66 75 6e 63 74 69 6f 6e 28  cate', function(
ab40: 29 20 7b 0a 0a 20 20 20 20 69 6e 6a 65 63 74 48  ) {..    injectH
ab50: 54 4d 4c 28 27 3c 6f 62 6a 2d 6b 65 79 2d 6c 6f  TML('<obj-key-lo
ab60: 6f 70 3e 3c 2f 6f 62 6a 2d 6b 65 79 2d 6c 6f 6f  op></obj-key-loo
ab70: 70 3e 27 29 0a 0a 20 20 20 20 63 6f 6e 73 74 20  p>')..    const 
ab80: 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74  tag = riot.mount
ab90: 28 27 6f 62 6a 2d 6b 65 79 2d 6c 6f 6f 70 27 29  ('obj-key-loop')
aba0: 5b 30 5d 0a 0a 20 20 20 20 65 78 70 65 63 74 28  [0]..    expect(
abb0: 74 61 67 2e 72 65 66 73 2e 78 2e 76 61 6c 75 65  tag.refs.x.value
abc0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 33  ).to.be.equal('3
abd0: 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61  ').    expect(ta
abe0: 67 2e 72 65 66 73 2e 79 2e 76 61 6c 75 65 29 2e  g.refs.y.value).
abf0: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 34 34 27  to.be.equal('44'
ac00: 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67  ).    expect(tag
ac10: 2e 72 65 66 73 2e 7a 2e 76 61 6c 75 65 29 2e 74  .refs.z.value).t
ac20: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 32 33 27 29  o.be.equal('23')
ac30: 0a 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74 65  ..    tag.update
ac40: 28 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61  ().    expect(ta
ac50: 67 2e 72 65 66 73 2e 78 2e 76 61 6c 75 65 29 2e  g.refs.x.value).
ac60: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 33 27 29  to.be.equal('3')
ac70: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e  .    expect(tag.
ac80: 72 65 66 73 2e 79 2e 76 61 6c 75 65 29 2e 74 6f  refs.y.value).to
ac90: 2e 62 65 2e 65 71 75 61 6c 28 27 34 34 27 29 0a  .be.equal('44').
aca0: 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 72      expect(tag.r
acb0: 65 66 73 2e 7a 2e 76 61 6c 75 65 29 2e 74 6f 2e  efs.z.value).to.
acc0: 62 65 2e 65 71 75 61 6c 28 27 32 33 27 29 0a 0a  be.equal('23')..
acd0: 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28      tag.unmount(
ace0: 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 6e 6f  ).  })..  it('no
acf0: 6e 20 6c 6f 6f 70 65 64 20 61 6e 64 20 63 6f 6e  n looped and con
ad00: 64 69 74 69 6f 6e 61 6c 20 76 69 72 74 75 61 6c  ditional virtual
ad10: 20 74 61 67 73 20 6d 6f 75 6e 74 20 63 6f 6e 74   tags mount cont
ad20: 65 6e 74 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29  ent', function()
ad30: 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d   {.    injectHTM
ad40: 4c 28 27 3c 76 69 72 74 75 61 6c 2d 6e 6f 2d 6c  L('<virtual-no-l
ad50: 6f 6f 70 3e 3c 2f 76 69 72 74 75 61 6c 2d 6e 6f  oop></virtual-no
ad60: 2d 6c 6f 6f 70 3e 27 29 0a 20 20 20 20 76 61 72  -loop>').    var
ad70: 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e   tag = riot.moun
ad80: 74 28 27 76 69 72 74 75 61 6c 2d 6e 6f 2d 6c 6f  t('virtual-no-lo
ad90: 6f 70 27 29 5b 30 5d 0a 0a 20 20 20 20 76 61 72  op')[0]..    var
ada0: 20 76 69 72 74 73 20 3d 20 24 24 28 27 76 69 72   virts = $$('vir
adb0: 74 75 61 6c 27 2c 20 74 61 67 2e 72 6f 6f 74 29  tual', tag.root)
adc0: 0a 20 20 20 20 65 78 70 65 63 74 28 76 69 72 74  .    expect(virt
add0: 73 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e  s.length).to.be.
ade0: 65 71 75 61 6c 28 30 29 0a 0a 20 20 20 20 76 61  equal(0)..    va
adf0: 72 20 73 70 61 6e 73 20 3d 20 24 24 28 27 73 70  r spans = $$('sp
ae00: 61 6e 27 2c 20 74 61 67 2e 72 6f 6f 74 29 0a 20  an', tag.root). 
ae10: 20 20 20 76 61 72 20 64 69 76 73 20 3d 20 24 24     var divs = $$
ae20: 28 27 64 69 76 27 2c 20 74 61 67 2e 72 6f 6f 74  ('div', tag.root
ae30: 29 0a 20 20 20 20 76 61 72 20 70 73 20 3d 20 24  ).    var ps = $
ae40: 24 28 27 70 27 2c 20 74 61 67 2e 72 6f 6f 74 29  $('p', tag.root)
ae50: 0a 20 20 20 20 65 78 70 65 63 74 28 73 70 61 6e  .    expect(span
ae60: 73 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e  s.length).to.be.
ae70: 65 71 75 61 6c 28 32 29 0a 20 20 20 20 65 78 70  equal(2).    exp
ae80: 65 63 74 28 64 69 76 73 2e 6c 65 6e 67 74 68 29  ect(divs.length)
ae90: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 32 29 0a  .to.be.equal(2).
aea0: 20 20 20 20 65 78 70 65 63 74 28 73 70 61 6e 73      expect(spans
aeb0: 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29 2e 74  [0].innerHTML).t
aec0: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 69 66 20 77  o.be.equal('if w
aed0: 6f 72 6b 73 20 74 65 78 74 27 29 0a 20 20 20 20  orks text').    
aee0: 65 78 70 65 63 74 28 64 69 76 73 5b 30 5d 2e 69  expect(divs[0].i
aef0: 6e 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e  nnerHTML).to.be.
af00: 65 71 75 61 6c 28 27 79 69 65 6c 64 65 64 20 74  equal('yielded t
af10: 65 78 74 27 29 0a 20 20 20 20 65 78 70 65 63 74  ext').    expect
af20: 28 73 70 61 6e 73 5b 31 5d 2e 69 6e 6e 65 72 48  (spans[1].innerH
af30: 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  TML).to.be.equal
af40: 28 27 76 69 72 74 75 61 6c 73 20 79 69 65 6c 64  ('virtuals yield
af50: 73 20 65 78 70 72 65 73 73 69 6f 6e 27 29 0a 20  s expression'). 
af60: 20 20 20 65 78 70 65 63 74 28 64 69 76 73 5b 31     expect(divs[1
af70: 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e  ].innerHTML).to.
af80: 62 65 2e 65 71 75 61 6c 28 27 68 65 6c 6c 6f 20  be.equal('hello 
af90: 74 68 65 72 65 27 29 0a 20 20 20 20 65 78 70 65  there').    expe
afa0: 63 74 28 70 73 2e 6c 65 6e 67 74 68 29 2e 74 6f  ct(ps.length).to
afb0: 2e 62 65 2e 65 71 75 61 6c 28 31 29 0a 20 20 20  .be.equal(1).   
afc0: 20 65 78 70 65 63 74 28 70 73 5b 30 5d 2e 69 6e   expect(ps[0].in
afd0: 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65  nerHTML).to.be.e
afe0: 71 75 61 6c 28 27 74 65 78 74 27 29 0a 0a 20 20  qual('text')..  
aff0: 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a    tag.unmount().
b000: 20 20 7d 29 0a 0a 0a 20 20 69 74 28 27 76 69 72    })...  it('vir
b010: 74 75 61 6c 20 74 61 67 73 20 77 69 74 68 20 79  tual tags with y
b020: 69 65 6c 64 65 64 20 63 6f 6e 74 65 6e 74 20 66  ielded content f
b030: 75 6e 63 74 69 6f 6e 20 69 6e 20 61 20 6c 6f 6f  unction in a loo
b040: 70 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b  p', function() {
b050: 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28  .    injectHTML(
b060: 27 3c 76 69 72 74 75 61 6c 2d 79 69 65 6c 64 2d  '<virtual-yield-
b070: 6c 6f 6f 70 3e 3c 2f 76 69 72 74 75 61 6c 2d 79  loop></virtual-y
b080: 69 65 6c 64 2d 6c 6f 6f 70 3e 27 29 0a 20 20 20  ield-loop>').   
b090: 20 63 6f 6e 73 74 20 74 61 67 20 3d 20 72 69 6f   const tag = rio
b0a0: 74 2e 6d 6f 75 6e 74 28 27 76 69 72 74 75 61 6c  t.mount('virtual
b0b0: 2d 79 69 65 6c 64 2d 6c 6f 6f 70 27 29 5b 30 5d  -yield-loop')[0]
b0c0: 0a 20 20 20 20 76 61 72 20 73 70 61 6e 73 20 3d  .    var spans =
b0d0: 20 24 24 28 27 73 70 61 6e 27 2c 20 74 61 67 2e   $$('span', tag.
b0e0: 72 6f 6f 74 29 0a 0a 20 20 20 20 65 78 70 65 63  root)..    expec
b0f0: 74 28 73 70 61 6e 73 5b 30 5d 2e 69 6e 6e 65 72  t(spans[0].inner
b100: 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65 71 75 61  HTML).to.be.equa
b110: 6c 28 27 6f 6e 65 27 29 0a 20 20 20 20 65 78 70  l('one').    exp
b120: 65 63 74 28 73 70 61 6e 73 5b 31 5d 2e 69 6e 6e  ect(spans[1].inn
b130: 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65 71  erHTML).to.be.eq
b140: 75 61 6c 28 27 74 77 6f 27 29 0a 20 20 20 20 65  ual('two').    e
b150: 78 70 65 63 74 28 73 70 61 6e 73 5b 32 5d 2e 69  xpect(spans[2].i
b160: 6e 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e  nnerHTML).to.be.
b170: 65 71 75 61 6c 28 27 74 68 72 65 65 27 29 0a 0a  equal('three')..
b180: 20 20 20 20 74 61 67 2e 69 74 65 6d 73 2e 72 65      tag.items.re
b190: 76 65 72 73 65 28 29 0a 20 20 20 20 74 61 67 2e  verse().    tag.
b1a0: 75 70 64 61 74 65 28 29 0a 0a 20 20 20 20 73 70  update()..    sp
b1b0: 61 6e 73 20 3d 20 24 24 28 27 73 70 61 6e 27 2c  ans = $$('span',
b1c0: 20 74 61 67 2e 72 6f 6f 74 29 0a 0a 20 20 20 20   tag.root)..    
b1d0: 65 78 70 65 63 74 28 73 70 61 6e 73 5b 30 5d 2e  expect(spans[0].
b1e0: 69 6e 6e 65 72 48 54 4d 4c 29 2e 74 6f 2e 62 65  innerHTML).to.be
b1f0: 2e 65 71 75 61 6c 28 27 74 68 72 65 65 27 29 0a  .equal('three').
b200: 20 20 20 20 65 78 70 65 63 74 28 73 70 61 6e 73      expect(spans
b210: 5b 31 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29 2e 74  [1].innerHTML).t
b220: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 74 77 6f 27  o.be.equal('two'
b230: 29 0a 20 20 20 20 65 78 70 65 63 74 28 73 70 61  ).    expect(spa
b240: 6e 73 5b 32 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29  ns[2].innerHTML)
b250: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 6f 6e  .to.be.equal('on
b260: 65 27 29 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d  e')..    tag.unm
b270: 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69  ount().  })..  i
b280: 74 28 27 6c 6f 6f 70 65 64 20 69 74 65 6d 73 20  t('looped items 
b290: 77 69 74 68 20 63 6f 6e 64 69 74 69 6f 6e 61 6c  with conditional
b2a0: 20 67 65 74 20 70 72 6f 70 65 72 6c 79 20 69 6e   get properly in
b2b0: 73 65 72 74 65 64 20 69 6e 74 6f 20 74 68 65 20  serted into the 
b2c0: 44 4f 4d 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29  DOM', function()
b2d0: 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d   {.    injectHTM
b2e0: 4c 28 27 3c 6c 6f 6f 70 2d 62 75 67 2d 31 36 34  L('<loop-bug-164
b2f0: 39 3e 3c 2f 6c 6f 6f 70 2d 62 75 67 2d 31 36 34  9></loop-bug-164
b300: 39 3e 27 29 0a 20 20 20 20 63 6f 6e 73 74 20 74  9>').    const t
b310: 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28  ag = riot.mount(
b320: 27 6c 6f 6f 70 2d 62 75 67 2d 31 36 34 39 27 29  'loop-bug-1649')
b330: 5b 30 5d 0a 20 20 20 20 76 61 72 20 63 68 69 6c  [0].    var chil
b340: 64 72 65 6e 0a 0a 20 20 20 20 63 68 69 6c 64 72  dren..    childr
b350: 65 6e 20 3d 20 24 24 28 27 2e 6c 69 73 74 27 2c  en = $$('.list',
b360: 20 74 61 67 2e 72 6f 6f 74 29 0a 20 20 20 20 65   tag.root).    e
b370: 78 70 65 63 74 28 63 68 69 6c 64 72 65 6e 2e 6c  xpect(children.l
b380: 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75  ength).to.be.equ
b390: 61 6c 28 32 29 0a 0a 20 20 20 20 66 69 72 65 45  al(2)..    fireE
b3a0: 76 65 6e 74 28 24 28 27 2e 72 65 6d 6f 76 65 27  vent($('.remove'
b3b0: 2c 20 63 68 69 6c 64 72 65 6e 5b 30 5d 29 2c 20  , children[0]), 
b3c0: 27 63 6c 69 63 6b 27 29 0a 0a 20 20 20 20 63 68  'click')..    ch
b3d0: 69 6c 64 72 65 6e 20 3d 20 24 24 28 27 2e 6c 69  ildren = $$('.li
b3e0: 73 74 27 2c 20 74 61 67 2e 72 6f 6f 74 29 0a 20  st', tag.root). 
b3f0: 20 20 20 65 78 70 65 63 74 28 63 68 69 6c 64 72     expect(childr
b400: 65 6e 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65  en.length).to.be
b410: 2e 65 71 75 61 6c 28 31 29 0a 0a 20 20 20 20 66  .equal(1)..    f
b420: 69 72 65 45 76 65 6e 74 28 74 61 67 2e 72 65 66  ireEvent(tag.ref
b430: 73 5b 27 66 6f 6c 64 65 72 2d 6c 69 6e 6b 2d 32  s['folder-link-2
b440: 27 5d 2c 20 27 63 6c 69 63 6b 27 29 0a 0a 20 20  '], 'click')..  
b450: 20 20 63 68 69 6c 64 72 65 6e 20 3d 20 24 24 28    children = $$(
b460: 27 2e 6c 69 73 74 27 2c 20 74 61 67 2e 72 6f 6f  '.list', tag.roo
b470: 74 29 0a 20 20 20 20 65 78 70 65 63 74 28 63 68  t).    expect(ch
b480: 69 6c 64 72 65 6e 2e 6c 65 6e 67 74 68 29 2e 74  ildren.length).t
b490: 6f 2e 62 65 2e 65 71 75 61 6c 28 32 29 0a 0a 20  o.be.equal(2).. 
b4a0: 20 20 20 66 69 72 65 45 76 65 6e 74 28 24 28 27     fireEvent($('
b4b0: 2e 72 65 6d 6f 76 65 27 2c 20 63 68 69 6c 64 72  .remove', childr
b4c0: 65 6e 5b 30 5d 29 2c 20 27 63 6c 69 63 6b 27 29  en[0]), 'click')
b4d0: 0a 0a 20 20 20 20 63 68 69 6c 64 72 65 6e 20 3d  ..    children =
b4e0: 20 24 24 28 27 2e 6c 69 73 74 27 2c 20 74 61 67   $$('.list', tag
b4f0: 2e 72 6f 6f 74 29 0a 20 20 20 20 65 78 70 65 63  .root).    expec
b500: 74 28 63 68 69 6c 64 72 65 6e 2e 6c 65 6e 67 74  t(children.lengt
b510: 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 31  h).to.be.equal(1
b520: 29 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75  )..    tag.unmou
b530: 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28  nt().  })..  it(
b540: 27 6c 6f 6f 70 65 64 20 69 74 65 6d 73 20 67 65  'looped items ge
b550: 74 20 72 65 6d 6f 76 65 64 20 70 72 6f 70 65 72  t removed proper
b560: 6c 79 20 73 65 65 20 68 74 74 70 73 3a 2f 2f 67  ly see https://g
b570: 69 74 68 75 62 2e 63 6f 6d 2f 72 69 6f 74 2f 72  ithub.com/riot/r
b580: 69 6f 74 2f 69 73 73 75 65 73 2f 32 32 34 30 27  iot/issues/2240'
b590: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20  , function() {. 
b5a0: 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c     injectHTML('<
b5b0: 6c 6f 6f 70 2d 62 75 67 2d 32 32 34 30 3e 3c 2f  loop-bug-2240></
b5c0: 6c 6f 6f 70 2d 62 75 67 2d 32 32 34 30 3e 27 29  loop-bug-2240>')
b5d0: 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d  .    const tag =
b5e0: 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c 6f 6f   riot.mount('loo
b5f0: 70 2d 62 75 67 2d 32 32 34 30 27 29 5b 30 5d 0a  p-bug-2240')[0].
b600: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e  .    expect(tag.
b610: 72 65 66 73 2e 69 74 65 6d 73 29 2e 74 6f 2e 68  refs.items).to.h
b620: 61 76 65 2e 6c 65 6e 67 74 68 28 74 61 67 2e 69  ave.length(tag.i
b630: 74 65 6d 73 2e 6c 65 6e 67 74 68 29 0a 20 20 20  tems.length).   
b640: 20 74 61 67 2e 69 74 65 6d 73 20 3d 20 5b 74 61   tag.items = [ta
b650: 67 2e 69 74 65 6d 73 5b 74 61 67 2e 69 74 65 6d  g.items[tag.item
b660: 73 2e 6c 65 6e 67 74 68 20 2d 20 31 5d 5d 0a 20  s.length - 1]]. 
b670: 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a     tag.update().
b680: 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 69      expect(tag.i
b690: 74 65 6d 73 29 2e 74 6f 2e 68 61 76 65 2e 6c 65  tems).to.have.le
b6a0: 6e 67 74 68 28 31 29 0a 20 20 20 20 2f 2f 20 54  ngth(1).    // T
b6b0: 4f 44 4f 3a 20 74 68 65 20 72 65 66 73 20 69 6e  ODO: the refs in
b6c0: 20 61 20 6c 69 73 74 20 73 68 6f 75 6c 64 20 62   a list should b
b6d0: 65 20 61 6c 77 61 79 73 20 61 6e 20 61 72 72 61  e always an arra
b6e0: 79 21 0a 20 20 20 20 2f 2f 65 78 70 65 63 74 28  y!.    //expect(
b6f0: 74 61 67 2e 72 65 66 73 2e 69 74 65 6d 73 29 2e  tag.refs.items).
b700: 74 6f 2e 68 61 76 65 2e 6c 65 6e 67 74 68 28 31  to.have.length(1
b710: 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67  ).    expect(tag
b720: 2e 72 65 66 73 2e 69 74 65 6d 73 2e 69 6e 6e 65  .refs.items.inne
b730: 72 48 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65 71 75  rHTML).to.be.equ
b740: 61 6c 28 74 61 67 2e 69 74 65 6d 73 5b 30 5d 2e  al(tag.items[0].
b750: 76 61 6c 75 65 29 0a 0a 20 20 20 20 74 61 67 2e  value)..    tag.
b760: 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a  unmount().  })..
b770: 20 20 69 74 28 27 6c 6f 6f 70 65 64 20 69 74 65    it('looped ite
b780: 6d 73 20 77 69 6c 6c 20 62 65 20 72 65 6e 64 65  ms will be rende
b790: 72 65 64 20 6b 65 65 70 69 6e 67 20 74 68 65 20  red keeping the 
b7a0: 72 69 67 68 74 20 6f 72 64 65 72 20 77 68 65 6e  right order when
b7b0: 20 73 6f 72 74 65 64 27 2c 20 66 75 6e 63 74 69   sorted', functi
b7c0: 6f 6e 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63  on() {.    injec
b7d0: 74 48 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 62 75 67  tHTML('<loop-bug
b7e0: 2d 32 32 30 35 3e 3c 2f 6c 6f 6f 70 2d 62 75 67  -2205></loop-bug
b7f0: 2d 32 32 30 35 3e 27 29 0a 20 20 20 20 63 6f 6e  -2205>').    con
b800: 73 74 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f  st tag = riot.mo
b810: 75 6e 74 28 27 6c 6f 6f 70 2d 62 75 67 2d 32 32  unt('loop-bug-22
b820: 30 35 27 29 5b 30 5d 0a 0a 20 20 20 20 65 78 70  05')[0]..    exp
b830: 65 63 74 28 74 61 67 2e 69 74 65 6d 73 29 2e 74  ect(tag.items).t
b840: 6f 2e 68 61 76 65 2e 6c 65 6e 67 74 68 28 74 61  o.have.length(ta
b850: 67 2e 69 74 65 6d 73 41 6d 6f 75 6e 74 29 0a 20  g.itemsAmount). 
b860: 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 72 65     expect(tag.re
b870: 66 73 2e 69 74 65 6d 73 29 2e 74 6f 2e 68 61 76  fs.items).to.hav
b880: 65 2e 6c 65 6e 67 74 68 28 74 61 67 2e 69 74 65  e.length(tag.ite
b890: 6d 73 41 6d 6f 75 6e 74 29 0a 0a 20 20 20 20 74  msAmount)..    t
b8a0: 61 67 2e 61 64 64 45 64 69 74 4c 69 73 74 28 29  ag.addEditList()
b8b0: 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74 65 28  .    tag.update(
b8c0: 29 0a 0a 20 20 20 20 65 78 70 65 63 74 28 74 61  )..    expect(ta
b8d0: 67 2e 69 74 65 6d 73 29 2e 74 6f 2e 68 61 76 65  g.items).to.have
b8e0: 2e 6c 65 6e 67 74 68 28 74 61 67 2e 69 74 65 6d  .length(tag.item
b8f0: 73 41 6d 6f 75 6e 74 29 0a 20 20 20 20 65 78 70  sAmount).    exp
b900: 65 63 74 28 74 61 67 2e 72 65 66 73 2e 69 74 65  ect(tag.refs.ite
b910: 6d 73 29 2e 74 6f 2e 68 61 76 65 2e 6c 65 6e 67  ms).to.have.leng
b920: 74 68 28 74 61 67 2e 69 74 65 6d 73 41 6d 6f 75  th(tag.itemsAmou
b930: 6e 74 29 0a 0a 20 20 20 20 65 78 70 65 63 74 28  nt)..    expect(
b940: 74 61 67 2e 72 65 66 73 2e 69 74 65 6d 73 5b 74  tag.refs.items[t
b950: 61 67 2e 69 74 65 6d 73 41 6d 6f 75 6e 74 20 2d  ag.itemsAmount -
b960: 20 31 5d 2e 74 65 78 74 43 6f 6e 74 65 6e 74 29   1].textContent)
b970: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 67  .to.be.equal(tag
b980: 2e 69 74 65 6d 73 5b 74 61 67 2e 69 74 65 6d 73  .items[tag.items
b990: 41 6d 6f 75 6e 74 20 2d 20 31 5d 2e 6e 61 6d 65  Amount - 1].name
b9a0: 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67  ).    expect(tag
b9b0: 2e 72 65 66 73 2e 69 74 65 6d 73 5b 74 61 67 2e  .refs.items[tag.
b9c0: 69 74 65 6d 73 41 6d 6f 75 6e 74 20 2d 20 32 5d  itemsAmount - 2]
b9d0: 2e 74 65 78 74 43 6f 6e 74 65 6e 74 29 2e 74 6f  .textContent).to
b9e0: 2e 62 65 2e 65 71 75 61 6c 28 74 61 67 2e 69 74  .be.equal(tag.it
b9f0: 65 6d 73 5b 74 61 67 2e 69 74 65 6d 73 41 6d 6f  ems[tag.itemsAmo
ba00: 75 6e 74 20 2d 20 32 5d 2e 6e 61 6d 65 29 0a 0a  unt - 2].name)..
ba10: 20 20 20 20 74 61 67 2e 61 64 64 45 64 69 74 4c      tag.addEditL
ba20: 69 73 74 28 29 0a 20 20 20 20 74 61 67 2e 75 70  ist().    tag.up
ba30: 64 61 74 65 28 29 0a 0a 20 20 20 20 65 78 70 65  date()..    expe
ba40: 63 74 28 74 61 67 2e 69 74 65 6d 73 29 2e 74 6f  ct(tag.items).to
ba50: 2e 68 61 76 65 2e 6c 65 6e 67 74 68 28 74 61 67  .have.length(tag
ba60: 2e 69 74 65 6d 73 41 6d 6f 75 6e 74 29 0a 20 20  .itemsAmount).  
ba70: 20 20 65 78 70 65 63 74 28 74 61 67 2e 72 65 66    expect(tag.ref
ba80: 73 2e 69 74 65 6d 73 29 2e 74 6f 2e 68 61 76 65  s.items).to.have
ba90: 2e 6c 65 6e 67 74 68 28 74 61 67 2e 69 74 65 6d  .length(tag.item
baa0: 73 41 6d 6f 75 6e 74 29 0a 0a 20 20 20 20 65 78  sAmount)..    ex
bab0: 70 65 63 74 28 74 61 67 2e 72 65 66 73 2e 69 74  pect(tag.refs.it
bac0: 65 6d 73 5b 74 61 67 2e 69 74 65 6d 73 41 6d 6f  ems[tag.itemsAmo
bad0: 75 6e 74 20 2d 20 31 5d 2e 74 65 78 74 43 6f 6e  unt - 1].textCon
bae0: 74 65 6e 74 29 2e 74 6f 2e 62 65 2e 65 71 75 61  tent).to.be.equa
baf0: 6c 28 74 61 67 2e 69 74 65 6d 73 5b 74 61 67 2e  l(tag.items[tag.
bb00: 69 74 65 6d 73 41 6d 6f 75 6e 74 20 2d 20 31 5d  itemsAmount - 1]
bb10: 2e 6e 61 6d 65 29 0a 20 20 20 20 65 78 70 65 63  .name).    expec
bb20: 74 28 74 61 67 2e 72 65 66 73 2e 69 74 65 6d 73  t(tag.refs.items
bb30: 5b 74 61 67 2e 69 74 65 6d 73 41 6d 6f 75 6e 74  [tag.itemsAmount
bb40: 20 2d 20 32 5d 2e 74 65 78 74 43 6f 6e 74 65 6e   - 2].textConten
bb50: 74 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74  t).to.be.equal(t
bb60: 61 67 2e 69 74 65 6d 73 5b 74 61 67 2e 69 74 65  ag.items[tag.ite
bb70: 6d 73 41 6d 6f 75 6e 74 20 2d 20 32 5d 2e 6e 61  msAmount - 2].na
bb80: 6d 65 29 0a 20 20 20 20 65 78 70 65 63 74 28 74  me).    expect(t
bb90: 61 67 2e 72 65 66 73 2e 69 74 65 6d 73 5b 74 61  ag.refs.items[ta
bba0: 67 2e 69 74 65 6d 73 41 6d 6f 75 6e 74 20 2d 20  g.itemsAmount - 
bbb0: 33 5d 2e 74 65 78 74 43 6f 6e 74 65 6e 74 29 2e  3].textContent).
bbc0: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 67 2e  to.be.equal(tag.
bbd0: 69 74 65 6d 73 5b 74 61 67 2e 69 74 65 6d 73 41  items[tag.itemsA
bbe0: 6d 6f 75 6e 74 20 2d 20 33 5d 2e 6e 61 6d 65 29  mount - 3].name)
bbf0: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e  .    expect(tag.
bc00: 72 65 66 73 2e 69 74 65 6d 73 5b 74 61 67 2e 69  refs.items[tag.i
bc10: 74 65 6d 73 41 6d 6f 75 6e 74 20 2d 20 34 5d 2e  temsAmount - 4].
bc20: 74 65 78 74 43 6f 6e 74 65 6e 74 29 2e 74 6f 2e  textContent).to.
bc30: 62 65 2e 65 71 75 61 6c 28 74 61 67 2e 69 74 65  be.equal(tag.ite
bc40: 6d 73 5b 74 61 67 2e 69 74 65 6d 73 41 6d 6f 75  ms[tag.itemsAmou
bc50: 6e 74 20 2d 20 34 5d 2e 6e 61 6d 65 29 0a 0a 20  nt - 4].name).. 
bc60: 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29     tag.unmount()
bc70: 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 6c 6f 6f  .  })..  it('loo
bc80: 70 65 64 20 74 61 67 73 20 73 68 6f 75 6c 64 20  ped tags should 
bc90: 62 65 20 69 6e 20 74 68 65 20 44 4f 4d 20 77 68  be in the DOM wh
bca0: 65 6e 20 74 68 65 69 72 20 22 6d 6f 75 6e 74 22  en their "mount"
bcb0: 20 65 76 65 6e 74 20 67 65 74 73 20 74 72 69 67   event gets trig
bcc0: 67 65 72 65 64 27 2c 20 66 75 6e 63 74 69 6f 6e  gered', function
bcd0: 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48  () {.    injectH
bce0: 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 62 75 67 2d 32  TML('<loop-bug-2
bcf0: 32 34 32 3e 3c 2f 6c 6f 6f 70 2d 62 75 67 2d 32  242></loop-bug-2
bd00: 32 34 32 3e 27 29 0a 20 20 20 20 63 6f 6e 73 74  242>').    const
bd10: 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e   tag = riot.moun
bd20: 74 28 27 6c 6f 6f 70 2d 62 75 67 2d 32 32 34 32  t('loop-bug-2242
bd30: 27 29 5b 30 5d 0a 20 20 20 20 74 61 67 2e 74 61  ')[0].    tag.ta
bd40: 67 73 5b 27 6c 6f 6f 70 2d 62 75 67 2d 32 32 34  gs['loop-bug-224
bd50: 32 2d 63 68 69 6c 64 27 5d 2e 66 6f 72 45 61 63  2-child'].forEac
bd60: 68 28 28 74 29 20 3d 3e 20 65 78 70 65 63 74 28  h((t) => expect(
bd70: 74 2e 69 6e 44 4f 4d 29 2e 74 6f 2e 62 65 2e 6f  t.inDOM).to.be.o
bd80: 6b 29 0a 20 20 20 20 74 61 67 2e 69 74 65 6d 73  k).    tag.items
bd90: 20 3d 20 74 61 67 2e 69 74 65 6d 73 2e 63 6f 6e   = tag.items.con
bda0: 63 61 74 28 5b 34 2c 20 35 2c 20 36 5d 29 0a 20  cat([4, 5, 6]). 
bdb0: 20 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a     tag.update().
bdc0: 20 20 20 20 74 61 67 2e 74 61 67 73 5b 27 6c 6f      tag.tags['lo
bdd0: 6f 70 2d 62 75 67 2d 32 32 34 32 2d 63 68 69 6c  op-bug-2242-chil
bde0: 64 27 5d 2e 66 6f 72 45 61 63 68 28 28 74 29 20  d'].forEach((t) 
bdf0: 3d 3e 20 65 78 70 65 63 74 28 74 2e 69 6e 44 4f  => expect(t.inDO
be00: 4d 29 2e 74 6f 2e 62 65 2e 6f 6b 29 0a 0a 20 20  M).to.be.ok)..  
be10: 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a    tag.unmount().
be20: 20 20 7d 29 0a 0a 20 20 69 74 28 27 6c 6f 6f 70    })..  it('loop
be30: 65 64 20 63 75 73 74 6f 6d 20 74 61 67 73 20 63  ed custom tags c
be40: 61 6e 20 75 70 64 61 74 65 20 70 72 6f 70 65 72  an update proper
be50: 6c 79 20 74 68 65 69 72 20 72 6f 6f 74 20 6e 6f  ly their root no
be60: 64 65 20 61 74 74 72 69 62 75 74 65 73 27 2c 20  de attributes', 
be70: 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20  function() {.   
be80: 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6c 6f   injectHTML('<lo
be90: 6f 70 2d 69 74 65 6d 73 2d 61 74 74 72 73 3e 3c  op-items-attrs><
bea0: 2f 6c 6f 6f 70 2d 69 74 65 6d 73 2d 61 74 74 72  /loop-items-attr
beb0: 73 3e 27 29 0a 20 20 20 20 63 6f 6e 73 74 20 74  s>').    const t
bec0: 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28  ag = riot.mount(
bed0: 27 6c 6f 6f 70 2d 69 74 65 6d 73 2d 61 74 74 72  'loop-items-attr
bee0: 73 27 29 5b 30 5d 0a 20 20 20 20 6c 65 74 20 73  s')[0].    let s
bef0: 75 62 74 61 67 31 2c 20 73 75 62 74 61 67 32 0a  ubtag1, subtag2.
bf00: 0a 20 20 20 20 3b 5b 73 75 62 74 61 67 31 2c 20  .    ;[subtag1, 
bf10: 73 75 62 74 61 67 32 5d 20 3d 20 74 61 67 2e 74  subtag2] = tag.t
bf20: 61 67 73 5b 27 6c 6f 6f 70 2d 69 74 65 6d 73 2d  ags['loop-items-
bf30: 61 74 74 72 73 2d 69 74 65 6d 27 5d 0a 20 20 20  attrs-item'].   
bf40: 20 65 78 70 65 63 74 28 73 75 62 74 61 67 31 2e   expect(subtag1.
bf50: 72 6f 6f 74 2e 67 65 74 41 74 74 72 69 62 75 74  root.getAttribut
bf60: 65 28 27 64 61 74 61 2d 63 6f 6c 6f 72 27 29 29  e('data-color'))
bf70: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 73 75 62  .to.be.equal(sub
bf80: 74 61 67 31 2e 63 6f 6c 6f 72 29 0a 20 20 20 20  tag1.color).    
bf90: 65 78 70 65 63 74 28 73 75 62 74 61 67 32 2e 72  expect(subtag2.r
bfa0: 6f 6f 74 2e 67 65 74 41 74 74 72 69 62 75 74 65  oot.getAttribute
bfb0: 28 27 64 61 74 61 2d 63 6f 6c 6f 72 27 29 29 2e  ('data-color')).
bfc0: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 73 75 62 74  to.be.equal(subt
bfd0: 61 67 32 2e 63 6f 6c 6f 72 29 0a 0a 20 20 20 20  ag2.color)..    
bfe0: 74 61 67 2e 69 74 65 6d 73 2e 66 6f 72 45 61 63  tag.items.forEac
bff0: 68 28 69 74 65 6d 20 3d 3e 20 69 74 65 6d 2e 63  h(item => item.c
c000: 6f 6c 6f 72 20 3d 20 69 74 65 6d 2e 63 6f 6c 6f  olor = item.colo
c010: 72 20 3d 3d 3d 20 27 6f 72 61 6e 67 65 27 20 3f  r === 'orange' ?
c020: 20 27 72 65 64 27 20 3a 20 27 6f 72 61 6e 67 65   'red' : 'orange
c030: 27 29 0a 20 20 20 20 74 61 67 2e 75 70 64 61 74  ').    tag.updat
c040: 65 28 29 0a 0a 20 20 20 20 3b 5b 73 75 62 74 61  e()..    ;[subta
c050: 67 31 2c 20 73 75 62 74 61 67 32 5d 20 3d 20 74  g1, subtag2] = t
c060: 61 67 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 69 74  ag.tags['loop-it
c070: 65 6d 73 2d 61 74 74 72 73 2d 69 74 65 6d 27 5d  ems-attrs-item']
c080: 0a 20 20 20 20 65 78 70 65 63 74 28 73 75 62 74  .    expect(subt
c090: 61 67 31 2e 72 6f 6f 74 2e 67 65 74 41 74 74 72  ag1.root.getAttr
c0a0: 69 62 75 74 65 28 27 64 61 74 61 2d 63 6f 6c 6f  ibute('data-colo
c0b0: 72 27 29 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  r')).to.be.equal
c0c0: 28 73 75 62 74 61 67 31 2e 63 6f 6c 6f 72 29 0a  (subtag1.color).
c0d0: 20 20 20 20 65 78 70 65 63 74 28 73 75 62 74 61      expect(subta
c0e0: 67 32 2e 72 6f 6f 74 2e 67 65 74 41 74 74 72 69  g2.root.getAttri
c0f0: 62 75 74 65 28 27 64 61 74 61 2d 63 6f 6c 6f 72  bute('data-color
c100: 27 29 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28  ')).to.be.equal(
c110: 73 75 62 74 61 67 32 2e 63 6f 6c 6f 72 29 0a 20  subtag2.color). 
c120: 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29     tag.unmount()
c130: 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 6c 6f 6f  .  })..  it('loo
c140: 70 65 64 20 63 75 73 74 6f 6d 20 74 61 67 73 20  ped custom tags 
c150: 73 68 6f 75 6c 64 6e 5c 27 74 20 64 69 73 70 61  shouldn\'t dispa
c160: 74 63 68 20 74 68 65 20 22 75 70 64 61 74 65 22  tch the "update"
c170: 20 61 6e 64 20 22 75 70 64 61 74 65 64 22 20 65   and "updated" e
c180: 76 65 6e 74 73 20 77 68 69 6c 65 20 6d 6f 75 6e  vents while moun
c190: 74 65 64 27 2c 20 28 64 6f 6e 65 29 20 3d 3e 20  ted', (done) => 
c1a0: 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c  {.    injectHTML
c1b0: 28 27 3c 72 69 6f 74 2d 74 6d 70 3e 3c 2f 72 69  ('<riot-tmp></ri
c1c0: 6f 74 2d 74 6d 70 3e 27 29 0a 0a 20 20 20 20 63  ot-tmp>')..    c
c1d0: 6f 6e 73 74 20 75 70 64 61 74 65 45 76 65 6e 74  onst updateEvent
c1e0: 20 3d 20 73 69 6e 6f 6e 2e 73 70 79 28 29 2c 0a   = sinon.spy(),.
c1f0: 20 20 20 20 20 20 75 70 64 61 74 65 64 45 76 65        updatedEve
c200: 6e 74 20 3d 20 73 69 6e 6f 6e 2e 73 70 79 28 29  nt = sinon.spy()
c210: 2c 0a 20 20 20 20 20 20 62 65 66 6f 72 65 4d 6f  ,.      beforeMo
c220: 75 6e 74 45 76 65 6e 74 20 3d 20 73 69 6e 6f 6e  untEvent = sinon
c230: 2e 73 70 79 28 29 2c 0a 20 20 20 20 20 20 62 65  .spy(),.      be
c240: 66 6f 72 65 55 6e 6d 6f 75 6e 74 45 76 65 6e 74  foreUnmountEvent
c250: 20 3d 20 73 69 6e 6f 6e 2e 73 70 79 28 29 2c 0a   = sinon.spy(),.
c260: 20 20 20 20 20 20 75 6e 6d 6f 75 6e 74 45 76 65        unmountEve
c270: 6e 74 20 3d 20 73 69 6e 6f 6e 2e 73 70 79 28 29  nt = sinon.spy()
c280: 2c 0a 20 20 20 20 20 20 6d 6f 75 6e 74 45 76 65  ,.      mountEve
c290: 6e 74 20 3d 20 73 69 6e 6f 6e 2e 73 70 79 28 29  nt = sinon.spy()
c2a0: 0a 0a 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27  ..    riot.tag('
c2b0: 72 69 6f 74 2d 74 6d 70 27 2c 20 27 3c 72 69 6f  riot-tmp', '<rio
c2c0: 74 2d 74 6d 70 2d 73 75 62 20 72 65 66 3d 22 63  t-tmp-sub ref="c
c2d0: 68 69 6c 64 72 65 6e 22 20 65 61 63 68 3d 22 7b  hildren" each="{
c2e0: 20 67 65 74 49 74 65 6d 73 28 29 20 7d 22 2f 3e   getItems() }"/>
c2f0: 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a  ', function() {.
c300: 20 20 20 20 20 20 74 68 69 73 2e 6f 6e 28 27 6d        this.on('m
c310: 6f 75 6e 74 27 2c 20 66 75 6e 63 74 69 6f 6e 28  ount', function(
c320: 29 20 7b 0a 20 20 20 20 20 20 20 20 74 68 69 73  ) {.        this
c330: 2e 75 70 64 61 74 65 28 29 0a 20 20 20 20 20 20  .update().      
c340: 7d 29 0a 0a 20 20 20 20 20 20 74 68 69 73 2e 6f  })..      this.o
c350: 6e 28 27 75 70 64 61 74 65 64 27 2c 20 28 29 20  n('updated', () 
c360: 3d 3e 20 7b 0a 20 20 20 20 20 20 20 20 73 65 74  => {.        set
c370: 54 69 6d 65 6f 75 74 28 28 29 20 3d 3e 20 7b 0a  Timeout(() => {.
c380: 20 20 20 20 20 20 20 20 20 20 65 78 70 65 63 74            expect
c390: 28 75 70 64 61 74 65 45 76 65 6e 74 2c 20 27 75  (updateEvent, 'u
c3a0: 70 64 61 74 65 20 65 76 65 6e 74 27 29 2e 74 6f  pdate event').to
c3b0: 2e 68 61 76 65 2e 6e 6f 74 2e 62 65 65 6e 2e 63  .have.not.been.c
c3c0: 61 6c 6c 65 64 0a 20 20 20 20 20 20 20 20 20 20  alled.          
c3d0: 65 78 70 65 63 74 28 75 70 64 61 74 65 64 45 76  expect(updatedEv
c3e0: 65 6e 74 2c 20 27 75 70 64 61 74 65 20 65 76 65  ent, 'update eve
c3f0: 6e 74 27 29 2e 74 6f 2e 68 61 76 65 2e 6e 6f 74  nt').to.have.not
c400: 2e 62 65 65 6e 2e 63 61 6c 6c 65 64 0a 20 20 20  .been.called.   
c410: 20 20 20 20 20 20 20 65 78 70 65 63 74 28 62 65         expect(be
c420: 66 6f 72 65 4d 6f 75 6e 74 45 76 65 6e 74 2c 20  foreMountEvent, 
c430: 27 62 65 66 6f 72 65 20 6d 6f 75 6e 74 20 65 76  'before mount ev
c440: 65 6e 74 27 29 2e 74 6f 2e 68 61 76 65 2e 62 65  ent').to.have.be
c450: 65 6e 2e 63 61 6c 6c 65 64 54 77 69 63 65 0a 20  en.calledTwice. 
c460: 20 20 20 20 20 20 20 20 20 65 78 70 65 63 74 28           expect(
c470: 6d 6f 75 6e 74 45 76 65 6e 74 2c 20 27 6d 6f 75  mountEvent, 'mou
c480: 6e 74 20 65 76 65 6e 74 27 29 2e 74 6f 2e 68 61  nt event').to.ha
c490: 76 65 2e 62 65 65 6e 2e 63 61 6c 6c 65 64 54 77  ve.been.calledTw
c4a0: 69 63 65 0a 20 20 20 20 20 20 20 20 20 20 65 78  ice.          ex
c4b0: 70 65 63 74 28 62 65 66 6f 72 65 55 6e 6d 6f 75  pect(beforeUnmou
c4c0: 6e 74 45 76 65 6e 74 2c 20 27 62 65 66 6f 72 65  ntEvent, 'before
c4d0: 20 75 6e 6d 6f 75 6e 74 20 65 76 65 6e 74 27 29   unmount event')
c4e0: 2e 74 6f 2e 68 61 76 65 2e 62 65 65 6e 2e 63 61  .to.have.been.ca
c4f0: 6c 6c 65 64 4f 6e 63 65 0a 20 20 20 20 20 20 20  lledOnce.       
c500: 20 20 20 65 78 70 65 63 74 28 75 6e 6d 6f 75 6e     expect(unmoun
c510: 74 45 76 65 6e 74 2c 20 27 75 6e 6d 6f 75 6e 74  tEvent, 'unmount
c520: 20 65 76 65 6e 74 27 29 2e 74 6f 2e 68 61 76 65   event').to.have
c530: 2e 62 65 65 6e 2e 63 61 6c 6c 65 64 4f 6e 63 65  .been.calledOnce
c540: 0a 20 20 20 20 20 20 20 20 20 20 74 68 69 73 2e  .          this.
c550: 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 20 20 20 20  unmount().      
c560: 20 20 20 20 64 6f 6e 65 28 29 0a 20 20 20 20 20      done().     
c570: 20 20 20 7d 2c 20 31 30 29 0a 20 20 20 20 20 20     }, 10).      
c580: 7d 29 0a 0a 20 20 20 20 20 20 74 68 69 73 2e 67  })..      this.g
c590: 65 74 49 74 65 6d 73 20 3d 20 28 29 20 3d 3e 20  etItems = () => 
c5a0: 7b 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e  {.        return
c5b0: 20 5b 7b 7d 5d 0a 20 20 20 20 20 20 7d 0a 20 20   [{}].      }.  
c5c0: 20 20 7d 29 0a 0a 20 20 20 20 72 69 6f 74 2e 74    })..    riot.t
c5d0: 61 67 28 27 72 69 6f 74 2d 74 6d 70 2d 73 75 62  ag('riot-tmp-sub
c5e0: 27 2c 20 27 3c 70 3e 73 75 62 74 61 67 3c 2f 70  ', '<p>subtag</p
c5f0: 3e 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b  >', function() {
c600: 0a 20 20 20 20 20 20 74 68 69 73 2e 6f 6e 28 27  .      this.on('
c610: 62 65 66 6f 72 65 2d 6d 6f 75 6e 74 27 2c 20 62  before-mount', b
c620: 65 66 6f 72 65 4d 6f 75 6e 74 45 76 65 6e 74 29  eforeMountEvent)
c630: 0a 20 20 20 20 20 20 74 68 69 73 2e 6f 6e 28 27  .      this.on('
c640: 6d 6f 75 6e 74 27 2c 20 6d 6f 75 6e 74 45 76 65  mount', mountEve
c650: 6e 74 29 0a 20 20 20 20 20 20 74 68 69 73 2e 6f  nt).      this.o
c660: 6e 28 27 75 70 64 61 74 65 27 2c 20 75 70 64 61  n('update', upda
c670: 74 65 45 76 65 6e 74 29 0a 20 20 20 20 20 20 74  teEvent).      t
c680: 68 69 73 2e 6f 6e 28 27 75 70 64 61 74 65 64 27  his.on('updated'
c690: 2c 20 75 70 64 61 74 65 64 45 76 65 6e 74 29 0a  , updatedEvent).
c6a0: 20 20 20 20 20 20 74 68 69 73 2e 6f 6e 28 27 62        this.on('b
c6b0: 65 66 6f 72 65 2d 75 6e 6d 6f 75 6e 74 27 2c 20  efore-unmount', 
c6c0: 62 65 66 6f 72 65 55 6e 6d 6f 75 6e 74 45 76 65  beforeUnmountEve
c6d0: 6e 74 29 0a 20 20 20 20 20 20 74 68 69 73 2e 6f  nt).      this.o
c6e0: 6e 28 27 75 6e 6d 6f 75 6e 74 27 2c 20 75 6e 6d  n('unmount', unm
c6f0: 6f 75 6e 74 45 76 65 6e 74 29 0a 20 20 20 20 7d  ountEvent).    }
c700: 29 0a 0a 20 20 20 20 72 69 6f 74 2e 6d 6f 75 6e  )..    riot.moun
c710: 74 28 27 72 69 6f 74 2d 74 6d 70 27 29 5b 30 5d  t('riot-tmp')[0]
c720: 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 6c 6f 6f  .  })..  it('loo
c730: 70 65 64 20 74 61 67 73 20 63 61 6e 20 70 72 6f  ped tags can pro
c740: 70 65 72 6c 79 20 72 65 63 65 69 76 65 20 70 61  perly receive pa
c750: 72 65 6e 74 20 70 72 6f 70 65 72 74 69 65 73 20  rent properties 
c760: 76 69 61 20 61 74 74 72 69 62 75 74 65 73 27 2c  via attributes',
c770: 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20   function() {.  
c780: 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 72    injectHTML('<r
c790: 69 6f 74 2d 74 6d 70 3e 3c 2f 72 69 6f 74 2d 74  iot-tmp></riot-t
c7a0: 6d 70 3e 27 29 0a 0a 20 20 20 20 72 69 6f 74 2e  mp>')..    riot.
c7b0: 74 61 67 28 27 72 69 6f 74 2d 74 6d 70 27 2c 20  tag('riot-tmp', 
c7c0: 27 3c 72 69 6f 74 2d 74 6d 70 2d 73 75 62 20 66  '<riot-tmp-sub f
c7d0: 75 6e 63 3d 7b 66 75 6e 63 7d 20 65 61 63 68 3d  unc={func} each=
c7e0: 22 7b 69 74 65 6d 73 7d 22 2f 3e 27 2c 20 66 75  "{items}"/>', fu
c7f0: 6e 63 74 69 6f 6e 28 6f 70 74 73 29 20 7b 0a 20  nction(opts) {. 
c800: 20 20 20 20 20 74 68 69 73 2e 66 75 6e 63 20 3d       this.func =
c810: 20 6f 70 74 73 2e 66 75 6e 63 0a 20 20 20 20 20   opts.func.     
c820: 20 74 68 69 73 2e 69 74 65 6d 73 20 3d 20 5b 31   this.items = [1
c830: 2c 20 32 2c 20 33 5d 0a 20 20 20 20 7d 29 0a 0a  , 2, 3].    })..
c840: 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27 72 69      riot.tag('ri
c850: 6f 74 2d 74 6d 70 2d 73 75 62 27 2c 20 27 27 2c  ot-tmp-sub', '',
c860: 20 66 75 6e 63 74 69 6f 6e 28 6f 70 74 73 29 20   function(opts) 
c870: 7b 0a 20 20 20 20 20 20 74 68 69 73 2e 6f 6e 28  {.      this.on(
c880: 27 6d 6f 75 6e 74 27 2c 20 6f 70 74 73 2e 66 75  'mount', opts.fu
c890: 6e 63 29 0a 20 20 20 20 7d 29 0a 0a 20 20 20 20  nc).    })..    
c8a0: 63 6f 6e 73 74 20 63 62 20 3d 20 73 69 6e 6f 6e  const cb = sinon
c8b0: 2e 73 70 79 28 29 0a 20 20 20 20 63 6f 6e 73 74  .spy().    const
c8c0: 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e   tag = riot.moun
c8d0: 74 28 27 72 69 6f 74 2d 74 6d 70 27 2c 20 7b 20  t('riot-tmp', { 
c8e0: 66 75 6e 63 3a 20 63 62 20 7d 29 5b 30 5d 0a 0a  func: cb })[0]..
c8f0: 20 20 20 20 65 78 70 65 63 74 28 63 62 29 2e 74      expect(cb).t
c900: 6f 2e 68 61 76 65 2e 62 65 65 6e 2e 63 61 6c 6c  o.have.been.call
c910: 65 64 54 68 72 69 63 65 0a 20 20 20 20 74 61 67  edThrice.    tag
c920: 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a  .unmount().  }).
c930: 0a 20 20 69 74 28 27 6f 62 6a 65 63 74 73 20 69  .  it('objects i
c940: 74 65 72 61 74 69 6f 6e 73 20 77 69 74 68 6f 75  terations withou
c950: 74 20 61 6e 79 20 22 6b 65 79 22 20 61 74 74 72  t any "key" attr
c960: 69 62 75 74 65 20 77 69 6c 6c 20 6e 6f 74 20 74  ibute will not t
c970: 72 69 67 67 65 72 20 75 6e 65 63 65 73 73 61 72  rigger unecessar
c980: 79 20 72 65 72 65 6e 64 65 72 73 20 28 69 73 73  y rerenders (iss
c990: 75 65 20 23 32 35 38 35 29 27 2c 20 66 75 6e 63  ue #2585)', func
c9a0: 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 69 6e 6a  tion() {.    inj
c9b0: 65 63 74 48 54 4d 4c 28 27 3c 72 69 6f 74 2d 74  ectHTML('<riot-t
c9c0: 6d 70 3e 3c 2f 72 69 6f 74 2d 74 6d 70 3e 27 29  mp></riot-tmp>')
c9d0: 0a 0a 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27  ..    riot.tag('
c9e0: 72 69 6f 74 2d 74 6d 70 27 2c 20 27 3c 70 20 72  riot-tmp', '<p r
c9f0: 65 66 3d 22 70 22 20 65 61 63 68 3d 22 7b 20 69  ef="p" each="{ i
ca00: 74 65 6d 73 20 7d 22 3e 3c 2f 70 3e 27 2c 20 66  tems }"></p>', f
ca10: 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20  unction() {.    
ca20: 20 20 74 68 69 73 2e 69 74 65 6d 73 20 3d 20 7b    this.items = {
ca30: 0a 20 20 20 20 20 20 20 20 61 3a 20 7b 7d 2c 0a  .        a: {},.
ca40: 20 20 20 20 20 20 20 20 62 3a 20 7b 7d 2c 0a 20          b: {},. 
ca50: 20 20 20 20 20 20 20 63 3a 20 7b 7d 2c 0a 20 20         c: {},.  
ca60: 20 20 20 20 20 20 64 3a 20 7b 7d 0a 20 20 20 20        d: {}.    
ca70: 20 20 7d 0a 20 20 20 20 7d 29 0a 20 20 20 20 63    }.    }).    c
ca80: 6f 6e 73 74 20 74 61 67 20 3d 20 72 69 6f 74 2e  onst tag = riot.
ca90: 6d 6f 75 6e 74 28 27 72 69 6f 74 2d 74 6d 70 27  mount('riot-tmp'
caa0: 29 5b 30 5d 0a 20 20 20 20 63 6f 6e 73 74 20 70  )[0].    const p
cab0: 73 20 3d 20 74 61 67 2e 72 65 66 73 2e 70 0a 0a  s = tag.refs.p..
cac0: 20 20 20 20 70 73 5b 30 5d 2e 73 65 74 41 74 74      ps[0].setAtt
cad0: 72 69 62 75 74 65 28 27 68 65 6c 6c 6f 27 2c 20  ribute('hello', 
cae0: 27 77 6f 72 6c 64 27 29 0a 20 20 20 20 74 61 67  'world').    tag
caf0: 2e 69 74 65 6d 73 20 3d 20 72 69 6f 74 2e 75 74  .items = riot.ut
cb00: 69 6c 2e 6d 69 73 63 2e 65 78 74 65 6e 64 28 7b  il.misc.extend({
cb10: 7d 2c 20 74 61 67 2e 69 74 65 6d 73 29 0a 20 20  }, tag.items).  
cb20: 20 20 74 61 67 2e 75 70 64 61 74 65 28 29 0a 0a    tag.update()..
cb30: 20 20 20 20 65 78 70 65 63 74 28 70 73 5b 30 5d      expect(ps[0]
cb40: 2e 67 65 74 41 74 74 72 69 62 75 74 65 28 27 68  .getAttribute('h
cb50: 65 6c 6c 6f 27 29 29 2e 74 6f 2e 62 65 2e 65 71  ello')).to.be.eq
cb60: 75 61 6c 28 27 77 6f 72 6c 64 27 29 0a 0a 20 20  ual('world')..  
cb70: 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a    tag.unmount().
cb80: 20 20 7d 29 0a 0a 20 20 69 74 28 27 74 68 65 20    })..  it('the 
cb90: 73 61 6d 65 20 6f 62 6a 65 63 74 20 63 61 6e 20  same object can 
cba0: 62 65 20 70 72 6f 70 65 72 6c 79 20 72 65 2d 61  be properly re-a
cbb0: 64 64 65 64 20 74 6f 20 61 20 63 6f 6c 6c 65 63  dded to a collec
cbc0: 74 69 6f 6e 20 28 69 73 73 75 65 20 23 32 36 30  tion (issue #260
cbd0: 30 29 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20  0)', function() 
cbe0: 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c  {.    injectHTML
cbf0: 28 27 3c 72 69 6f 74 2d 74 6d 70 3e 3c 2f 72 69  ('<riot-tmp></ri
cc00: 6f 74 2d 74 6d 70 3e 27 29 0a 0a 20 20 20 20 63  ot-tmp>')..    c
cc10: 6f 6e 73 74 20 69 74 65 6d 20 3d 20 7b 7d 0a 0a  onst item = {}..
cc20: 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27 72 69      riot.tag('ri
cc30: 6f 74 2d 74 6d 70 27 2c 20 27 3c 70 20 72 65 66  ot-tmp', '<p ref
cc40: 3d 22 70 22 20 65 61 63 68 3d 22 7b 20 69 74 65  ="p" each="{ ite
cc50: 6d 73 20 7d 22 3e 68 65 6c 6c 6f 3c 2f 70 3e 27  ms }">hello</p>'
cc60: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20  , function() {. 
cc70: 20 20 20 20 20 74 68 69 73 2e 69 74 65 6d 73 20       this.items 
cc80: 3d 20 5b 69 74 65 6d 5d 0a 20 20 20 20 7d 29 0a  = [item].    }).
cc90: 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d  .    const tag =
cca0: 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 72 69 6f   riot.mount('rio
ccb0: 74 2d 74 6d 70 27 29 5b 30 5d 0a 0a 20 20 20 20  t-tmp')[0]..    
ccc0: 74 61 67 2e 69 74 65 6d 73 2e 70 75 73 68 28 69  tag.items.push(i
ccd0: 74 65 6d 29 0a 20 20 20 20 74 61 67 2e 75 70 64  tem).    tag.upd
cce0: 61 74 65 28 29 0a 0a 20 20 20 20 65 78 70 65 63  ate()..    expec
ccf0: 74 28 74 61 67 2e 72 65 66 73 2e 70 29 2e 74 6f  t(tag.refs.p).to
cd00: 2e 68 61 76 65 2e 6c 65 6e 67 74 68 28 32 29 0a  .have.length(2).
cd10: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
cd20: 28 29 0a 20 20 7d 29 0a 0a 0a 20 20 69 74 28 27  ().  })...  it('
cd30: 41 6c 6c 20 74 68 65 20 69 74 65 6d 73 20 69 6e  All the items in
cd40: 64 65 78 65 73 20 61 72 65 20 69 6e 63 72 65 6d  dexes are increm
cd50: 65 6e 74 61 6c 6c 79 20 67 65 6e 65 72 61 74 65  entally generate
cd60: 64 20 61 6c 73 6f 20 69 6e 20 63 61 73 65 20 6f  d also in case o
cd70: 66 20 69 66 20 73 74 61 74 65 6d 65 6e 74 73 20  f if statements 
cd80: 69 6e 20 61 20 6c 6f 6f 70 20 28 69 73 73 75 65  in a loop (issue
cd90: 20 23 32 36 30 33 29 27 2c 20 66 75 6e 63 74 69   #2603)', functi
cda0: 6f 6e 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63  on() {.    injec
cdb0: 74 48 54 4d 4c 28 27 3c 72 69 6f 74 2d 74 6d 70  tHTML('<riot-tmp
cdc0: 3e 3c 2f 72 69 6f 74 2d 74 6d 70 3e 27 29 0a 0a  ></riot-tmp>')..
cdd0: 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27 72 69      riot.tag('ri
cde0: 6f 74 2d 74 6d 70 27 2c 20 27 3c 70 20 72 65 66  ot-tmp', '<p ref
cdf0: 3d 22 70 22 20 65 61 63 68 3d 22 7b 20 69 74 65  ="p" each="{ ite
ce00: 6d 2c 20 69 20 69 6e 20 69 74 65 6d 73 20 7d 22  m, i in items }"
ce10: 20 69 66 3d 22 7b 20 69 20 21 3d 3d 20 30 20 7d   if="{ i !== 0 }
ce20: 22 3e 7b 69 7d 3c 2f 70 3e 27 2c 20 66 75 6e 63  ">{i}</p>', func
ce30: 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 20 20 74  tion() {.      t
ce40: 68 69 73 2e 69 74 65 6d 73 20 3d 20 5b 7b 7d 2c  his.items = [{},
ce50: 20 7b 7d 2c 20 7b 7d 5d 0a 20 20 20 20 7d 29 0a   {}, {}].    }).
ce60: 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67 20 3d  .    const tag =
ce70: 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 72 69 6f   riot.mount('rio
ce80: 74 2d 74 6d 70 27 29 5b 30 5d 0a 0a 20 20 20 20  t-tmp')[0]..    
ce90: 65 78 70 65 63 74 28 74 61 67 2e 72 65 66 73 2e  expect(tag.refs.
cea0: 70 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29 2e  p[0].innerHTML).
ceb0: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 31 27 29  to.be.equal('1')
cec0: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e  .    expect(tag.
ced0: 72 65 66 73 2e 70 5b 31 5d 2e 69 6e 6e 65 72 48  refs.p[1].innerH
cee0: 54 4d 4c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c  TML).to.be.equal
cef0: 28 27 32 27 29 0a 0a 20 20 20 20 74 61 67 2e 75  ('2')..    tag.u
cf00: 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 2f  nmount().  })../
cf10: 2a 0a 20 20 54 4f 44 4f 3a 20 6e 65 73 74 65 64  *.  TODO: nested
cf20: 20 72 65 66 73 20 61 6e 64 20 74 61 67 73 20 73   refs and tags s
cf30: 68 6f 75 6c 64 20 62 65 20 69 6e 20 73 79 6e 63  hould be in sync
cf40: 0a 20 20 69 74 28 27 6e 65 73 74 65 64 20 74 61  .  it('nested ta
cf50: 67 73 20 67 65 74 20 70 72 6f 70 65 72 6c 79 20  gs get properly 
cf60: 6d 6f 76 65 64 27 2c 20 66 75 6e 63 74 69 6f 6e  moved', function
cf70: 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48  () {.    injectH
cf80: 54 4d 4c 28 27 3c 6c 6f 6f 70 2d 6e 65 73 74 65  TML('<loop-neste
cf90: 64 3e 3c 2f 6c 6f 6f 70 2d 6e 65 73 74 65 64 3e  d></loop-nested>
cfa0: 27 29 0a 20 20 20 20 63 6f 6e 73 74 20 74 61 67  ').    const tag
cfb0: 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6c   = riot.mount('l
cfc0: 6f 6f 70 2d 6e 65 73 74 65 64 27 29 5b 30 5d 0a  oop-nested')[0].
cfd0: 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 74      expect(tag.t
cfe0: 61 67 73 5b 27 6c 6f 6f 70 2d 6e 65 73 74 65 64  ags['loop-nested
cff0: 2d 69 74 65 6d 27 5d 5b 30 5d 2e 76 61 6c 29 2e  -item'][0].val).
d000: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 31 29 0a 20  to.be.equal(1). 
d010: 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 72 65     expect(tag.re
d020: 66 73 2e 70 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d  fs.p[0].innerHTM
d030: 4c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27  L).to.be.equal('
d040: 31 27 29 0a 20 20 20 20 74 61 67 2e 69 74 65 6d  1').    tag.item
d050: 73 2e 72 65 76 65 72 73 65 28 29 0a 20 20 20 20  s.reverse().    
d060: 74 61 67 2e 75 70 64 61 74 65 28 29 0a 20 20 20  tag.update().   
d070: 20 65 78 70 65 63 74 28 74 61 67 2e 72 65 66 73   expect(tag.refs
d080: 2e 70 5b 30 5d 2e 69 6e 6e 65 72 48 54 4d 4c 29  .p[0].innerHTML)
d090: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 33 27  .to.be.equal('3'
d0a0: 29 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67  ).    expect(tag
d0b0: 2e 74 61 67 73 5b 27 6c 6f 6f 70 2d 6e 65 73 74  .tags['loop-nest
d0c0: 65 64 2d 69 74 65 6d 27 5d 5b 30 5d 2e 76 61 6c  ed-item'][0].val
d0d0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 33 29  ).to.be.equal(3)
d0e0: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74  .    tag.unmount
d0f0: 28 29 0a 20 20 7d 29 0a 0a 2a 2f 0a 7d 29 0a     ().  })..*/.}).