api.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. describe('UNIT: API', function () {
  2. describe('config()', function () {
  3. it('should work when changing prefix', function () {
  4. var testId = 'config-1'
  5. Seed.config({
  6. prefix: 'test'
  7. })
  8. mock(testId, '<span test-text="test"></span>')
  9. new Seed({
  10. el: '#' + testId,
  11. scope: { test: testId }
  12. })
  13. assert.strictEqual(document.querySelector('#' + testId + ' span').innerHTML, testId)
  14. })
  15. after(function () {
  16. Seed.config({
  17. prefix: 'sd'
  18. })
  19. })
  20. })
  21. describe('filter()', function () {
  22. var reverse = function (input) {
  23. return input.split('').reverse().join('')
  24. }
  25. it('should create custom filter', function () {
  26. var testId = 'filter-1',
  27. msg = '12345'
  28. Seed.filter('reverse', reverse)
  29. mock(testId, '{{ test | reverse }}')
  30. new Seed({
  31. el: '#' + testId,
  32. scope: { test: msg }
  33. })
  34. assert.strictEqual(document.querySelector('#' + testId).innerHTML, '54321')
  35. })
  36. it('should return filter function if only one arg is given', function () {
  37. var f = Seed.filter('reverse')
  38. assert.strictEqual(f, reverse)
  39. })
  40. })
  41. describe('directive()', function () {
  42. var dirTest
  43. it('should create custom directive with set function only', function () {
  44. var testId = 'directive-1',
  45. msg = 'wowow'
  46. Seed.directive('test', function (value) {
  47. this.el.setAttribute(testId, value + '123')
  48. })
  49. mock(testId, '<span sd-test="test"></span>')
  50. new Seed({
  51. el: '#' + testId,
  52. scope: { test: msg }
  53. })
  54. var el = document.querySelector('#' + testId + ' span')
  55. assert.strictEqual(el.getAttribute(testId), msg + '123')
  56. })
  57. it('should create custom directive with object', function () {
  58. var testId = 'directive-2',
  59. msg = 'wowaaaa?'
  60. dirTest = {
  61. bind: function (value) {
  62. this.el.setAttribute(testId + 'bind', value + 'bind')
  63. },
  64. update: function (value) {
  65. this.el.setAttribute(testId + 'update', value + 'update')
  66. },
  67. unbind: function () {
  68. this.el.removeAttribute(testId + 'bind')
  69. }
  70. }
  71. Seed.directive('test2', dirTest)
  72. mock(testId, '<span sd-test2="test"></span>')
  73. var vm = new Seed({
  74. el: '#' + testId,
  75. scope: { test: msg }
  76. }),
  77. el = document.querySelector('#' + testId + ' span')
  78. assert.strictEqual(el.getAttribute(testId + 'bind'), msg + 'bind', 'should have called bind()')
  79. assert.strictEqual(el.getAttribute(testId + 'update'), msg + 'update', 'should have called update()')
  80. vm.$destroy() // assuming this works
  81. assert.notOk(el.getAttribute(testId + 'bind'), 'should have called unbind()')
  82. })
  83. it('should return directive object/fn if only one arg is given', function () {
  84. var dir = Seed.directive('test2')
  85. assert.strictEqual(dir, dirTest)
  86. })
  87. })
  88. describe('component()', function () {
  89. var testId = 'api-component-test',
  90. testId2 = testId + '2',
  91. opts = {
  92. className: 'hihi',
  93. scope: { hi: 'ok' }
  94. },
  95. Test = Seed.extend(opts),
  96. utils = require('seed/src/utils')
  97. it('should register a Component constructor', function () {
  98. Seed.component(testId, Test)
  99. assert.strictEqual(utils.components[testId], Test)
  100. })
  101. it('should also work with option objects', function () {
  102. Seed.component(testId2, opts)
  103. assert.ok(utils.components[testId2].prototype instanceof Seed)
  104. })
  105. it('should retrieve the VM if has only one arg', function () {
  106. assert.strictEqual(Seed.component(testId), Test)
  107. })
  108. it('should work with sd-component', function () {
  109. mock(testId, '<div sd-component="' + testId + '">{{hi}}</div>')
  110. var t = new Seed({ el: '#' + testId }),
  111. child = t.$el.querySelector('div')
  112. assert.strictEqual(child.className, 'hihi')
  113. assert.strictEqual(child.textContent, 'ok')
  114. mock(testId2, '<div sd-component="' + testId2 + '">{{hi}}</div>')
  115. var t2 = new Seed({ el: '#' + testId2 }),
  116. child2 = t2.$el.querySelector('div')
  117. assert.strictEqual(child2.className, 'hihi')
  118. assert.strictEqual(child2.textContent, 'ok')
  119. })
  120. })
  121. describe('element()', function () {
  122. var testId = 'api-element-test',
  123. testId2 = testId + '2',
  124. testId3 = testId + '3',
  125. opts = {
  126. className: 'hihi',
  127. scope: { hi: 'ok' }
  128. },
  129. Test = Seed.extend(opts),
  130. utils = require('seed/src/utils')
  131. it('should register a Custom Element constructor', function () {
  132. Seed.element(testId, Test)
  133. assert.strictEqual(utils.elements[testId], Test)
  134. })
  135. it('should also work with option objects', function () {
  136. Seed.element(testId2, opts)
  137. assert.ok(utils.elements[testId2].prototype instanceof Seed)
  138. })
  139. it('should accept simple function as-is', function () {
  140. var fn = function (el) {
  141. el.className = 'hihi3'
  142. el.textContent = 'ok3'
  143. }
  144. Seed.element(testId3, fn)
  145. assert.strictEqual(utils.elements[testId3], fn)
  146. })
  147. it('should retrieve the VM if has only one arg', function () {
  148. assert.strictEqual(Seed.element(testId), Test)
  149. })
  150. it('should work with custom tag names', function () {
  151. mock(testId, '<' + testId + '>{{hi}}</' + testId + '>')
  152. var t = new Seed({ el: '#' + testId }),
  153. child = t.$el.querySelector(testId)
  154. assert.strictEqual(child.className, 'hihi')
  155. assert.strictEqual(child.textContent, 'ok')
  156. mock(testId2, '<' + testId2 + '>{{hi}}</' + testId2 + '>')
  157. var t2 = new Seed({ el: '#' + testId2 }),
  158. child2 = t2.$el.querySelector(testId2)
  159. assert.strictEqual(child2.className, 'hihi')
  160. assert.strictEqual(child2.textContent, 'ok')
  161. mock(testId3, '<' + testId3 + '></' + testId3 + '>')
  162. var t3 = new Seed({ el: '#' + testId3 }),
  163. child3 = t3.$el.querySelector(testId3)
  164. assert.strictEqual(child3.className, 'hihi3')
  165. assert.strictEqual(child3.textContent, 'ok3')
  166. })
  167. })
  168. describe('partial()', function () {
  169. var testId = 'api-partial-test',
  170. partial = '<div class="partial-test"><a>{{hi}}</a></div><span>hahaha</span>',
  171. utils = require('seed/src/utils')
  172. it('should register the partial as a dom fragment', function () {
  173. Seed.partial(testId, partial)
  174. var converted = utils.partials[testId]
  175. assert.ok(converted instanceof window.DocumentFragment)
  176. assert.strictEqual(converted.querySelector('.partial-test a').innerHTML, '{{hi}}')
  177. assert.strictEqual(converted.querySelector('span').innerHTML, 'hahaha')
  178. })
  179. it('should retrieve the partial if has only one arg', function () {
  180. assert.strictEqual(utils.partials[testId], Seed.partial(testId))
  181. })
  182. it('should work with sd-partial as a directive', function () {
  183. var testId = 'api-partial-direcitve'
  184. Seed.partial(testId, partial)
  185. mock(testId, '<div class="directive" sd-partial="' + testId + '">hello</div>')
  186. var t = new Seed({
  187. el: '#' + testId,
  188. scope: { hi: 'hohoho' }
  189. })
  190. assert.strictEqual(t.$el.querySelector('.directive .partial-test a').textContent, 'hohoho')
  191. assert.strictEqual(t.$el.querySelector('.directive span').innerHTML, 'hahaha')
  192. })
  193. it('should work with sd-partial as an inline interpolation', function () {
  194. var testId = 'api-partial-inline'
  195. Seed.partial(testId, partial)
  196. mock(testId, '<div class="inline">{{>' + testId + '}}</div>')
  197. var t = new Seed({
  198. el: '#' + testId,
  199. scope: { hi: 'hohoho' }
  200. })
  201. assert.strictEqual(t.$el.querySelector('.inline .partial-test a').textContent, 'hohoho')
  202. assert.strictEqual(t.$el.querySelector('.inline span').innerHTML, 'hahaha')
  203. })
  204. })
  205. describe('transition()', function () {
  206. var testId = 'api-trans-test',
  207. transition = {},
  208. utils = require('seed/src/utils')
  209. it('should register a transition object', function () {
  210. Seed.transition(testId, transition)
  211. assert.strictEqual(utils.transitions[testId], transition)
  212. })
  213. it('should retrieve the transition if has only one arg', function () {
  214. assert.strictEqual(Seed.transition(testId), transition)
  215. })
  216. it('should work with sd-transition', function () {
  217. var enterCalled = false,
  218. leaveCalled = false
  219. Seed.transition('transition-api-test', {
  220. enter: function (el, done) {
  221. enterCalled = true
  222. done()
  223. },
  224. leave: function (el, done) {
  225. leaveCalled = true
  226. done()
  227. }
  228. })
  229. var t = new Seed({
  230. attributes: {
  231. 'sd-show': 'show',
  232. 'sd-transition': 'transition-api-test'
  233. },
  234. scope: {
  235. show: false
  236. }
  237. })
  238. document.body.appendChild(t.$el)
  239. t.show = true
  240. assert.ok(enterCalled)
  241. assert.strictEqual(t.$el.style.display, '')
  242. t.show = false
  243. assert.ok(leaveCalled)
  244. assert.strictEqual(t.$el.style.display, 'none')
  245. t.$destroy()
  246. })
  247. })
  248. describe('extend()', function () {
  249. it('should return a subclass of Seed', function () {
  250. var Test = Seed.extend({})
  251. assert.ok(Test.prototype instanceof Seed)
  252. })
  253. it('should allow further extensions', function () {
  254. var Parent = Seed.extend({
  255. scope: {
  256. test: 'hi'
  257. }
  258. })
  259. var Child = Parent.extend({
  260. scope: {
  261. test2: 'ho',
  262. test3: {
  263. hi: 1
  264. }
  265. }
  266. })
  267. assert.strictEqual(Child.super, Parent)
  268. var child = new Child({
  269. scope: {
  270. test3: {
  271. ho: 2
  272. }
  273. }
  274. })
  275. assert.strictEqual(child.test, 'hi')
  276. assert.strictEqual(child.test2, 'ho')
  277. // should overwrite past 1 level deep
  278. assert.strictEqual(child.test3.ho, 2)
  279. assert.notOk(child.test3.hi)
  280. })
  281. describe('Options', function () {
  282. describe('init', function () {
  283. it('should be called on the instance when instantiating', function () {
  284. var called = false,
  285. Test = Seed.extend({ init: function () {
  286. called = true
  287. }})
  288. new Test({ el: document.createElement('div') })
  289. assert.ok(called)
  290. })
  291. })
  292. describe('proto', function () {
  293. it('should be mixed to the exteded VM\'s prototype', function () {
  294. var mixins = {
  295. a: 1,
  296. b: 2,
  297. c: function () {}
  298. }
  299. var Test = Seed.extend({ proto: mixins })
  300. for (var key in mixins) {
  301. assert.strictEqual(Test.prototype[key], mixins[key])
  302. }
  303. })
  304. })
  305. describe('scope', function () {
  306. it('should be copied to each instance', function () {
  307. var testData = { a: 1 },
  308. Test = Seed.extend({
  309. scope: {
  310. test: testData
  311. }
  312. })
  313. var t1 = new Test(),
  314. t2 = new Test()
  315. assert.ok(t1.hasOwnProperty('test'))
  316. assert.strictEqual(t1.test, testData)
  317. assert.ok(t2.hasOwnProperty('test'))
  318. assert.strictEqual(t2.test, testData)
  319. })
  320. })
  321. describe('lazy', function () {
  322. it('should make text input fields only trigger on change', function () {
  323. var Test = Seed.extend({
  324. template: '<input type="text" sd-model="test">',
  325. lazy: true
  326. })
  327. var t = new Test({
  328. scope: {
  329. test: 'hi'
  330. }
  331. })
  332. var input = t.$el.querySelector('input')
  333. input.value = 'hohoho'
  334. input.dispatchEvent(mockHTMLEvent('input'))
  335. assert.strictEqual(t.test, 'hi')
  336. input.dispatchEvent(mockHTMLEvent('change'))
  337. assert.strictEqual(t.test, 'hohoho')
  338. })
  339. })
  340. describe('replace', function () {
  341. it('should replace an in DOM node', function () {
  342. var testId = 'replace-test'
  343. mock(testId, '<div>ho</div>')
  344. var old = document.getElementById(testId),
  345. parent = old.parentNode
  346. var Test = Seed.extend({
  347. template: '<p>hi</p>',
  348. replace: true
  349. })
  350. var t = new Test({
  351. el: '#' + testId
  352. })
  353. assert.strictEqual(t.$el.tagName, 'P')
  354. assert.strictEqual(t.$el.textContent, 'hi')
  355. assert.strictEqual(t.$el.parentNode, parent)
  356. var now = document.getElementById(testId)
  357. assert.strictEqual(now, null)
  358. })
  359. it('should replace an off DOM Seed\'s $el', function () {
  360. var Test = Seed.extend({
  361. template: '<p>hi</p>',
  362. replace: true
  363. })
  364. var t = new Test()
  365. assert.strictEqual(t.$el.tagName, 'P')
  366. assert.strictEqual(t.$el.textContent, 'hi')
  367. })
  368. it('should not work if template has more than one child node', function () {
  369. var Test = Seed.extend({
  370. template: '<p>hi</p><p>ho</p>',
  371. replace: true
  372. })
  373. var t = new Test()
  374. assert.notStrictEqual(t.$el.tagName, 'P')
  375. assert.strictEqual(t.$el.innerHTML, '<p>hi</p><p>ho</p>')
  376. })
  377. })
  378. describe('element options', function () {
  379. it('should not accept el as an extension option', function () {
  380. var el = document.createElement('div'),
  381. Test = Seed.extend({ el: el }),
  382. t = new Test()
  383. assert.notStrictEqual(t.$el, el)
  384. })
  385. it('should create el with options: tagName, id, className and attributes', function () {
  386. var Test = Seed.extend({
  387. tagName: 'p',
  388. id: 'extend-test',
  389. className: 'extend',
  390. attributes: {
  391. 'test': 'hi',
  392. 'sd-text': 'hoho'
  393. },
  394. scope: {
  395. hoho: 'what'
  396. }
  397. })
  398. var t = new Test()
  399. assert.strictEqual(t.$el.nodeName, 'P', 'tagName should match')
  400. assert.strictEqual(t.$el.id, 'extend-test', 'id should match')
  401. assert.strictEqual(t.$el.className, 'extend', 'className should match')
  402. assert.strictEqual(t.$el.getAttribute('test'), 'hi', 'normal attr should work')
  403. assert.strictEqual(t.$el.textContent, 'what', 'directives passed in as attr should work')
  404. })
  405. it('should ignore tagName when el is passed as an instance option', function () {
  406. var el = document.createElement('div'),
  407. Test = Seed.extend({
  408. tagName: 'p',
  409. id: 'extend-test',
  410. className: 'extend',
  411. attributes: {
  412. 'test': 'hi',
  413. 'sd-text': 'hoho'
  414. },
  415. scope: {
  416. hoho: 'what'
  417. }
  418. }),
  419. t = new Test({
  420. el: el
  421. })
  422. assert.strictEqual(t.$el, el, 'should use instance el')
  423. assert.notStrictEqual(t.$el.nodeName, 'P', 'tagName should NOT match')
  424. assert.strictEqual(t.$el.id, 'extend-test', 'id should match')
  425. assert.strictEqual(t.$el.className, 'extend', 'className should match')
  426. assert.strictEqual(t.$el.getAttribute('test'), 'hi', 'normal attr should work')
  427. assert.strictEqual(t.$el.textContent, 'what', 'directives passed in as attr should work')
  428. })
  429. })
  430. describe('template', function () {
  431. var raw = '<span>{{hello}}</span><a>haha</a>'
  432. it('should take direct string template and work', function () {
  433. var Test = Seed.extend({
  434. tagName: 'p',
  435. template: raw,
  436. scope: {
  437. hello: 'Ahaha'
  438. }
  439. }),
  440. vm = new Test(),
  441. text1 = vm.$el.querySelector('span').textContent,
  442. text2 = vm.$el.querySelector('a').textContent
  443. assert.strictEqual(vm.$el.nodeName, 'P')
  444. assert.strictEqual(text1, 'Ahaha')
  445. assert.strictEqual(text2, 'haha')
  446. })
  447. it('should take a #id and work', function () {
  448. var testId = 'template-test',
  449. tpl = document.createElement('script')
  450. tpl.id = testId
  451. tpl.type = 'text/template'
  452. tpl.innerHTML = raw
  453. document.getElementById('test').appendChild(tpl)
  454. var Test = Seed.extend({
  455. template: '#' + testId,
  456. scope: { hello: testId }
  457. })
  458. var t = new Test()
  459. assert.strictEqual(t.$el.querySelector('span').textContent, testId)
  460. })
  461. it('should be overwritable', function () {
  462. var Test = Seed.extend({
  463. template: '<div>this should not happen</div>'
  464. })
  465. var t = new Test({
  466. template: raw,
  467. scope: {
  468. hello: 'overwritten!'
  469. }
  470. })
  471. assert.strictEqual(t.$el.querySelector('span').textContent, 'overwritten!')
  472. })
  473. })
  474. describe('directives', function () {
  475. it('should allow the VM to use private directives', function () {
  476. var Test = Seed.extend({
  477. directives: {
  478. test: function (value) {
  479. this.el.innerHTML = value ? 'YES' : 'NO'
  480. }
  481. }
  482. })
  483. var t = new Test({
  484. attributes: {
  485. 'sd-test': 'ok'
  486. },
  487. scope: {
  488. ok: true
  489. }
  490. })
  491. assert.strictEqual(t.$el.innerHTML, 'YES')
  492. t.ok = false
  493. assert.strictEqual(t.$el.innerHTML, 'NO')
  494. })
  495. })
  496. describe('filters', function () {
  497. it('should allow the VM to use private filters', function () {
  498. var Test = Seed.extend({
  499. filters: {
  500. test: function (value) {
  501. return value + '12345'
  502. }
  503. }
  504. })
  505. var t = new Test({
  506. template: '{{hi | test}}',
  507. scope: {
  508. hi: 'hohoho'
  509. }
  510. })
  511. assert.strictEqual(t.$el.textContent, 'hohoho12345')
  512. })
  513. })
  514. describe('components', function () {
  515. it('should allow the VM to use private child VMs', function () {
  516. var Child = Seed.extend({
  517. scope: {
  518. name: 'child'
  519. }
  520. })
  521. var Parent = Seed.extend({
  522. template: '<p>{{name}}</p><div sd-component="child">{{name}}</div>',
  523. scope: {
  524. name: 'dad'
  525. },
  526. components: {
  527. child: Child
  528. }
  529. })
  530. var p = new Parent()
  531. assert.strictEqual(p.$el.querySelector('p').textContent, 'dad')
  532. assert.strictEqual(p.$el.querySelector('div').textContent, 'child')
  533. })
  534. it('should work with plain option object', function () {
  535. var Parent = Seed.extend({
  536. template: '<p>{{name}}</p><div sd-component="child">{{name}}</div>',
  537. scope: {
  538. name: 'dad'
  539. },
  540. components: {
  541. child: {
  542. scope: {
  543. name: 'child'
  544. }
  545. }
  546. }
  547. })
  548. var p = new Parent()
  549. assert.strictEqual(p.$el.querySelector('p').textContent, 'dad')
  550. assert.strictEqual(p.$el.querySelector('div').textContent, 'child')
  551. })
  552. })
  553. describe('elements', function () {
  554. it('should allow the VM to use private custom elements', function () {
  555. var Child = Seed.extend({
  556. scope: {
  557. name: 'child'
  558. }
  559. })
  560. var Parent = Seed.extend({
  561. template: '<p>{{name}}</p><child>{{name}}</child>',
  562. scope: {
  563. name: 'dad'
  564. },
  565. elements: {
  566. child: Child
  567. }
  568. })
  569. var p = new Parent()
  570. assert.strictEqual(p.$el.querySelector('p').textContent, 'dad')
  571. assert.strictEqual(p.$el.querySelector('child').textContent, 'child')
  572. })
  573. it('should work with plain option object', function () {
  574. var Parent = Seed.extend({
  575. template: '<p>{{name}}</p><child>{{name}}</child>',
  576. scope: {
  577. name: 'dad'
  578. },
  579. elements: {
  580. child: {
  581. scope: {
  582. name: 'child'
  583. }
  584. }
  585. }
  586. })
  587. var p = new Parent()
  588. assert.strictEqual(p.$el.querySelector('p').textContent, 'dad')
  589. assert.strictEqual(p.$el.querySelector('child').textContent, 'child')
  590. })
  591. it('should work with a simple function', function () {
  592. var Parent = Seed.extend({
  593. template: '<p>{{name}}</p><child></child>',
  594. scope: {
  595. name: 'dad'
  596. },
  597. elements: {
  598. child: function (el) {
  599. el.textContent = 'child'
  600. }
  601. }
  602. })
  603. var p = new Parent()
  604. assert.strictEqual(p.$el.querySelector('p').textContent, 'dad')
  605. assert.strictEqual(p.$el.querySelector('child').textContent, 'child')
  606. })
  607. })
  608. describe('partials', function () {
  609. it('should allow the VM to use private partials', function () {
  610. var Test = Seed.extend({
  611. attributes: {
  612. 'sd-partial': 'test'
  613. },
  614. partials: {
  615. test: '<a>{{a}}</a><p>{{b}}</p>'
  616. },
  617. scope: {
  618. a: 'hi',
  619. b: 'ho'
  620. }
  621. })
  622. var t = new Test()
  623. assert.strictEqual(t.$el.querySelector('a').textContent, 'hi')
  624. assert.strictEqual(t.$el.querySelector('p').textContent, 'ho')
  625. })
  626. })
  627. describe('teardown', function () {
  628. it('should be called when a vm is destroyed', function () {
  629. var called = false
  630. var Test = Seed.extend({
  631. teardown: function () {
  632. called = true
  633. }
  634. })
  635. var test = new Test()
  636. test.$destroy()
  637. assert.ok(called)
  638. })
  639. })
  640. describe('transitions', function () {
  641. it('should get called during transitions', function () {
  642. var enterCalled = false,
  643. leaveCalled = false
  644. var t = new Seed({
  645. attributes: {
  646. 'sd-show': 'show',
  647. 'sd-transition': 'test'
  648. },
  649. transitions: {
  650. test: {
  651. enter: function (el, done) {
  652. enterCalled = true
  653. done()
  654. },
  655. leave: function (el, done) {
  656. leaveCalled = true
  657. done()
  658. }
  659. }
  660. },
  661. scope: {
  662. show: false
  663. }
  664. })
  665. document.body.appendChild(t.$el)
  666. t.show = true
  667. assert.ok(enterCalled)
  668. assert.strictEqual(t.$el.style.display, '')
  669. t.show = false
  670. assert.ok(leaveCalled)
  671. assert.strictEqual(t.$el.style.display, 'none')
  672. t.$destroy()
  673. })
  674. })
  675. })
  676. })
  677. })