|
1 | 1 | /* global testNode */ |
2 | 2 | import { applyBindings } from '@tko/bind' |
3 | 3 |
|
4 | | -import { observable, observableArray } from '@tko/observable' |
| 4 | +import { observable, ObservableArray, observableArray } from '@tko/observable' |
5 | 5 |
|
6 | 6 | import { DataBindProvider } from '@tko/provider.databind' |
7 | 7 |
|
@@ -141,17 +141,25 @@ describe('Native template engine', function () { |
141 | 141 | + "(Val: <span data-bind='text: $data'></span>, Invocations: <span data-bind='text: $root.invocationCount()'></span>, Parents: <span data-bind='text: $parents.length'></span>)" |
142 | 142 | + '</div>' |
143 | 143 | + '</div>' |
144 | | - const viewModel = { |
145 | | - invocations: 0, // Verifying # invocations to be sure we're not rendering anything multiple times and discarding the results |
146 | | - items: observableArray([ |
147 | | - { children: observableArray(['A1', 'A2', 'A3']) }, |
148 | | - { children: observableArray(['B1', 'B2']) } |
149 | | - ]), |
150 | | - invocationCount: undefined |
| 144 | + |
| 145 | + class myViewModel { |
| 146 | + invocations: number = 0 // Verifying # invocations to be sure we're not rendering anything multiple times and discarding the results |
| 147 | + items: ObservableArray<any> |
| 148 | + |
| 149 | + constructor() { |
| 150 | + this.items = observableArray([ |
| 151 | + { children: observableArray(['A1', 'A2', 'A3']) }, |
| 152 | + { children: observableArray(['B1', 'B2']) } |
| 153 | + ]) |
| 154 | + } |
| 155 | + |
| 156 | + invocationCount() { |
| 157 | + return ++this.invocations |
| 158 | + } |
151 | 159 | } |
152 | | - viewModel.invocationCount = function () { |
153 | | - return ++this.invocations |
154 | | - }.bind(viewModel) |
| 160 | + |
| 161 | + const viewModel = new myViewModel() |
| 162 | + |
155 | 163 | applyBindings(viewModel, testNode) |
156 | 164 |
|
157 | 165 | expect(testNode.childNodes[0].childNodes[0]).toContainText( |
|
0 commit comments